Initial use of jspSmartUpload, use of jspSmartUpload

Source: Internet
Author: User

Initial use of jspSmartUpload, use of jspSmartUpload

 

Use SmartUpload in jsp to upload files

1. Download The jspSmartUpload component and decompress it. Copy the com directory to the WEB-INF \ classes directory of the application.

2. Pay special attention

(1) Add enctype = "multipart/form-data" to the file upload form, for example:

<Form action = "product_update_ OK .jsp? P_id = <% = p_id %> "method =" post "onSubmit =" return check_product (this); "enctype =" multipart/form-data ">

(2) For file upload forms, the value of form items cannot be obtained through the request object, which must be obtained through the Request class provided by the jspSmartUpload component, for example:

String p_name = su. getRequest (). getParameter ("p_name ");

The Code should be placed after the file upload code.

3. Main Code

// Create an upload object
SmartUpload su = new SmartUpload ();
// Upload Initialization
Su. initialize (pageContext );
// Set upload restrictions
// Limit the maximum length of each uploaded file.
// Su. setMaxFileSize (10000 );
// Limit the total length of uploaded data.
// Su. setTotalMaxFileSize (20000 );
// Use the extension limit to set files that can be uploaded. Only doc and txt files are allowed here.
// Su. setAllowedFilesList ("doc, txt ");
// Use the extension to restrict files that are not allowed to be uploaded. Do not upload files with the exe, bat, jsp, htm, html extension, or files without the extension.
// Su. setDeniedFilesList ("exe, bat, jsp, htm, html ,,");
// Implement File Upload
Su. upload ();
// Save all uploaded files to the specified directory. The images directory must exist in the application root folder.
// Int count = su. save ("/images", su. SAVE_VIRTUAL );
Int count = su. save ("/images ");
String p_image_temp = "";
If (count = 1) // re-upload the image
{
Com. jspsmart. upload. File file = su. getFiles (). getFile (0 );
P_image_temp = "images \" + file. getFileName ();
}
Else
P_image_temp = (String) session. getAttribute ("p_iamge"); // The image is not uploaded again.

// Obtain other form information
String p_id = su. getRequest (). getParameter ("p_id ");
String p_type = su. getRequest (). getParameter ("p_type ");
String p_name = su. getRequest (). getParameter ("p_name ");
String p_price = su. getRequest (). getParameter ("p_price ");
String p_quantity = su. getRequest (). getParameter ("p_quantity ");
String p_description = su. getRequest (). getParameter ("p_description ");
String p_time = String. valueOf (date. getMonth () + 1) + "-" + date. getDate () + "-20" + String. valueOf (date. getYear ()). substring (1 );

Related Article

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.