JspsmartUpload Upload File (2)

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.