Several upload methods (JSPSmart, O`Reilly, Struts) introduction and comparison (original)

xiaoxiao2021-03-06  72

Several uploading methods, comparison

Author: Wang Zhiwei

2004-10-10 directory

1 Introduction

2 O`rilly-cos.

3 jspsmartupload.

4 Jakarta Apache struts upload.

More than 5 methods

1 Introduction

A site is always inevitable to interact with the user, if it is a simple input type (for example, text, password, radio, checkbox, select, etc.) to the server side, as long as you use Application / X-WWW-form-urlencoded encoding can be passed in session. But when it comes to file exchange between users (including uploading and downloading), it is not that simple. When uploading files to the server, you must use the Multipart / Form-Data encoding method and cannot be used directly to use Request.getParameter (). As for the methods used, such as JSPSMART's JSPSMARTupload Components, O`rilly COS Components, Jakarta Apache's CommonsFileUpload Components, JavaZoom's UploadBean Components, and ORG.Apache.Struts comes with Struts Components . UPLOAD Tool, etc. The following is a simple introduction and comparison for three solutions (JSPSmartupload, O`Reilly-Cos, Struts.upload).

2 o`rilly-cos

The COS component is developed by O`rilly, the component is free, and new features are not regularly added.

Figure 1 O`rilly-cos

In the COS component, the MultipartRequest class is primarily responsible for the processing uploaded by the file. MultipartRequest has 8 constructor:

1.Public MultipArtRequest (httpservletRequest Request, String Savedirectory,) THROWS IOEXCEPTION

2.Public MultipArtRequest (httpservletRequest Request, String Savedirectory, Int Maxpostsize) Throws oException

3.Public MultipArtRequest (httpservletRequest, String Savedirectory, Int MaxPostsize, Fileres IOException) Throws oException

4.Public MultipArtRequest (httpservletRequest Request, String Savedirectory, Int Maxpostsize, String Encoding) THROWS IOEXCEPTION

5.Public MultipartRequest (httpservletRequest Request, String Savedirectory, int maping, fileerenamepolicy policy) Throws oException

6.public MultipArtRequest (httpservletRequest Request, String Savedirectory, String Encoding) THROWS IOEXCEPTION

7.Public MultipartRequest (HttpServletRequest request, String saveDirectory) throws IOException8.Public MultipartRequest (HttpServletRequest request, String saveDirectory, int maxPostSize) throws IOException

The first 6 constructors are used to deal with the HTTP protocol. SaveDirectory is the directory name to be uploaded to be stored on the server side; MAXPOSTSIZE is used to limit the user upload file size, if you exceed MAXPOSTSZIE, will generate ioException, default upload file size Is 1MB; Encoding can set the file name to upload file names, can solve Chinese problems.

MultipartRequest tools have 8 ways, using these methods, we can get the relevant information about the request:

Public Enumeration getParameterNames ()

The name of the request parameter can be obtained

Public String getParameter (String name)

This method passes the value of the parameter name Name

Public string [] getParameterValers (String name)

This method is mainly used in obtaining the array of string when a specified parameter has multiple values.

Public enumeration getFileName ()

Remove the name of all file input types

Public String getFileSystemNames (String name)

Use this method to get the true file name of the upload file, the name of the NAME finger file input type

Public String getContentType (String Name)

This method gets the content type of uploaded files

Public file getfile (String name)

This method gets a file object that represents the name file stored on the server.

Public String getoriginalFileName (String name)

Returns the file name before the modification policy is valid

3 jspsmartupload

The JSPSmartupLoad component is developed by JSPSMART, and after installing its components, you can handle the file upload and download issues. This component is simple and easy, but the source code is not open.

JSPSMARTUPLOAD OVERVIEW:

Free

Upload 1OR More Files To The Server can upload 1 or more files

Upload to a database upload file to database

Control the upload file by file can be uploaded by one column (one)

Manage Mixed Forms Files Form Fields can manage table files and table domains

Download a file to implement file download

Download A Database Field can download from the database

Restrict File Size, Extension ETC can limit the size and type of uploaded files

Macbinary Support MCKBINARY Support

Platform: Apache, NT, UNIX, Linux, IIS can run on a variety of platforms

Database: mysql, oracle ... support multiple databases (most support MySQL)

The entire JSPSMARTUPLOAD compression package 113K, including examples, API descriptions, and compiled Class files, calling these Class files to upload the file upload download function. Figure 2 JSPSMARTUPOAD

JSPSmartupLoad can achieve more methods than O`rilly-Cos, such as:

1.public int getSize () method gets the sum of the uploaded file size

2.Public void setDeniedFilesList (String DeniedFileSlist) Method Set the type of user not uploading

3.Public Void SetAllowedFileSlist (String ALLOWEDFILSLIST) Method to set the file type uploaded by the user

4.Public void setTotalMaxFileSize (long TotalMaxFileSlist) Sets the summary of the upload file size

5.Public int getCount () gets the number of files in Files

6.public boolean ismissing () test file does already exist

7.public string getfieldname () get the table name in the previous HTML file

8.public string getfilepathname () Get this file in the uploaded file location

9.public string getfileext () gets the file extension

..........

JSPSMARTupLoad installation: Just copy these Class files to the Classes folder.

4

Jakarta

Apache Struts Upload

Since I have developed with Struts, it is uploaded using Struts, which combines the integral of the project, and does not need to import other packages, and the function is powerful, and the performance is stable. Open source, so it is undoubtedly the best choice.

The figure below is the structure of the UPLOAD package in Struts. Basically to achieve uploading, as long as the FormFiles and MultipartRequestHandler interfaces can be solved.

Figure 3 Structure of Struts-Upload package

The basic processing process is to pass the files into the Form from the page, then get the file in the Form from Action, form inputStream, and then write to disk via OutputStream.

Similarly, the Struts's UPLOAD tool class can also implement control of the upload file size and type, you can upload multiple files simultaneously.

More than 5 methods

O`rilly-cos

JSPSmartupload

Struts-upload

Whether open source

Yes Yes?

Is it whether it continues to develop?

Yes No unclear

Usually more reliability

High high

Characteristics review

Free, open source, unpredictless increase in new features, high reliability, code directly written in JSP files, upload, download, powerful, free, but source code is not open, code is written directly in the JSP file. When uploaded, the file is pre-read into the memory, and when it is received to the Save instruction, save it to the disk, so upload performance and file and memory size relationship are closely related. Using extremely convenient, free, open source, reliability in Struts, indicating layer and business layer, background FORM and ACTION

Table 1 Comparison of several uploading methods

After studying these severned components, I think no matter which one of them can meet my requirements, after all, we are just the function of the file upload. The most basic, as long as the file can get the file, you can achieve a wide variety of functions.

Conclusion Yes, for the Struts project, use the struts-upload component is the most appropriate choice; if you want to make a package, it is best to choose JSPSMARTupload and O`rilly-Cos. Resources:

1, O`Reilly COS component download address: http://www.servlets.com/cos/cos-05nov2002.zip2, because JSPSmart has stopped development, its official website has been closed, so the jspsmartupload component is almost extinct online, persevering The reader can go to Google on searching, and must also find Email if it is too trouble, I will send you in the past, 113k3, struts-upload components In the apache Struts1.1, you can go www.apache .org download

转载请注明原文地址:https://www.9cbs.com/read-108598.html

New Post(0)