Jspsmart2.jsp % @ pageimportcom. jspsmart. upload. * % @ pagecontentTypetexthtml; charsetGB2312 % htmlheadtitleJspsmart2.jsptitleheadbodyh2 File upload example
Jspsmart2.jsp % @ page import = com. jspsmart. upload. * % @ page contentType = text/html; charset = GB2312 % html head titleJspsmart2.jsp/title/head body h2 File Upload example-jspSmart/h2 jsp: useBean id = mySmartUpload scope = page class = com. jspsmart. uploa
Jspsmart2.jsp
<% @ Page import = "com. jspsmart. upload. *" %>
<% @ Page contentType = "text/html; charset = GB2312" %>
Jspsmart2.jsp
File Upload example-jspSmart
<%
// Calculate the number of file uploads
Int count = 0;
// SmartUpload initialization. To use this jspsmart, you must declare it at the beginning.
MySmartUpload. initialize (pageContext );
// Upload Based on the form Content
MySmartUpload. upload ();
// Extract uploaded files one by one for processing
For (int I = 0; I {
// Retrieve an object
Com. jspsmart. upload. File myFile = mySmartUpload. getFiles (). getFile (I );
// If the object exists, archive the object
If (! MyFile. isMissing ()){
// Store the object in an absolute path
MyFile. saveAs ("D: // totalExample // jsp // UploadFile //" + myFile. getFileName (), mySmartUpload. SAVE_PHYSICAL );
// Display the details of the uploaded file
Out. println ("FieldName =" + myFile. getFieldName () +"
");
Out. println ("Size =" + myFile. getSize () +"
");
Out. println ("FileName =" + myFile. getFileName () +"
");
Out. println ("FileExt =" + myFile. getFileExt () +"
");
Out. println ("FilePathName =" + myFile. getFilePathName () +"
");
Out. println ("ContentType =" + myFile. getContentType () +"
");
Out. println ("ContentDisp =" + myFile. getContentDisp () +"
");
Out. println ("TypeMIME =" + myFile. getTypeMIME () +"
");
Out. println ("SubTypeMIME =" + myFile. getSubTypeMIME () +"
");
Count ++;
}
}
// Display the number of objects to be uploaded
Out. println ("
"+ MySmartUpload. getFiles (). getCount () +" files cocould be uploaded.
");
// Display the number of successfully uploaded files
Out. println (count + "file (s) uploaded .");
%>
Note:
Generally, when the input type (such as text, password, select, and so on) is transferred to the server, the encoding method is application/x-www-Form-urlencoded, however, to transfer files to the server, you must use the mutilpart/form-data encoding method;