It turns out that the jspsmart class is a useful class for processing jsp file uploads, but the reuqest of the jsp built-in object is invalid because the form adds the enctype attribute, I didn't want to solve it. A few days ago, someone suddenly asked me this question and I couldn't answer it for a moment. I checked it online, the original jspsamrt toolkit not only contains the SmartFile class for processing uploaded files, but also a class SmartRequest that replaces the built-in object of the request. Below we will repost the sample code on the receiving page,
<% @ Page contentType = "text/html; charset = utf8" language = "java"
Import = "jspsmart. *" errorPage = "" %>
<Title> File Upload processing page </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = utf8">
<%
// Create a new SmartUpload object
SmartUpload su = new SmartUpload ();
// Upload Initialization
Su. initialize (pageContext );
// Set upload restrictions
// 1. Limit the maximum length of each uploaded file.
// Su. setMaxFileSize (10000 );
// 2. Restrict the total length of uploaded data.
// Su. setTotalMaxFileSize (20000 );
// 3. Set the files that can be uploaded (with the extension limit). Only the doc and txt files are allowed.
// Su. setAllowedFilesList ("doc, txt ");
// 4. Set files that are not allowed to be uploaded (by using the extension limit). Upload with exe, bat, is prohibited,
// Jsp, htm, html extension files and files without extension.
// Su. setDeniedFilesList ("exe, bat, jsp, htm, html ,,");
// Upload a file
Su. upload ();
// Save all uploaded files to the specified directory
Int count = su. save ("../webapps /");
Out. println (count + "files uploaded successfully! <Br/> ");
// Obtain the parameter value using the Request object
Out. println ("TEST =" +Su. getrequest (). getparameter ("test ")
+ "<BR> ");
// Extract the uploaded file information one by one and save the file.
For (int I = 0; I <su. getFiles (). getCount (); I ++)
{
Jspsmart. SmartFile file = su. getFiles (). getFile (I );
// Continue if the object does not exist
If (file. isMissing () continue;
// Display the current file information
Out. println ("<table border = 1> ");
Out. println ("<TR> <TD> form Item Name (FieldName) </TD> <TD>"
+ File. getFieldName () + "</TD> </TR> ");
Out. println ("<TR> <TD> file Size </TD> <TD>" +
File. getSize () + "</TD> </TR> ");
Out. println ("<TR> <TD> file name (FileName) </TD> <TD>"
+ File. getFileName () + "</TD> </TR> ");
Out. println ("<TR> <TD> file extension (FileExt) </TD> <TD>"
+ File. getFileExt () + "</TD> </TR> ");
Out. println ("<TR> <TD> file full name (FilePathName) </TD> <TD>"
+ File. getFilePathName () + "</TD> </TR> ");
Out. println ("</TABLE> <BR> ");
// Save the file
// File. saveAs ("/upload/" + myFile. getFileName ());
// Save it to the directory where the root directory of the WEB application is the root directory of the file.
// File. saveAs ("/upload/" + myFile. getFileName (), su. SAVE_VIRTUAL );
// Save the file to the root directory of the Operating System
// File. saveas ("C: // temp //" + myfile. getfilename (), Su. save_physical );
}
%>
It is worth noting that there is a method for this smartrequestGetparamtervalues ("string") can get an array of objects with the same name defined on the previous page. For example:
<Input type = "text" name = "test"/>
<Input type = "text" name = "test"/>
<Input type = "text" name = "test"/>
UseSu. getrequest (). getparametervalues ("test") to get an array.