Ajax implementation of File upload and background servlet in the processing summary

Source: Internet
Author: User

First to share the resources found at that time (10 jquery Ajax File Upload Plug-ins, some plug-ins business will charge, pay attention to copyright): http://superdit.com/2010/06/29/10-jquery-ajax-file-uploader-plugins/

At that time their own needs is to upload multiple pictures and other form input data, after the trial of each plug-in finally selected the tenth plug-in is Jqupload:http://jqframework.com/jqupload

The data type for form form submission is: Multipart/form-data, there are several solutions to the form's data that cannot be obtained directly through GetParameter () in the servlet:

A.multipartrequest class: Http://www.servlets.com/cos/javadoc/com/oreilly/servlet/MultipartRequest.html use method reference: http:/ /hi.baidu.com/%b3%ac%bc%b6%ce%de%b5%d0xiaoq/blog/item/d66b9aa3ae073781471064e9.html/cmtid/ a78728f8ea497f9a59ee908b

B.smartupload class: Use the method reference http://tech.ddvip.com/2008-12/122853517497938.html and http://www.iteye.com/topic/255010

C.struts can be processed automatically (not tried)

Finally, choose to use smartupload for implementation.

::::: To be accustomed to using Google search English resources to solve their own problems.




Front-end upload form and JS in the Jqupload download has a simple code to achieve, simply add the form element as required.

The code in the servlet is referenced as follows:

Smartupload mysmartupload = new Smartupload ();
Mysmartupload.initialize (Getservletconfig (), request,response);
try {
Mysmartupload.upload ();
catch (Smartuploadexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
Request req = Mysmartupload.getrequest ();
for (int i = 0; i < Mysmartupload.getfiles (). GetCount (); i++) {
Com.jspsmart.upload.File File = Mysmartupload.getfiles (). GetFile (i);
if (file.ismissing ()) continue;
try {
File.saveas ("z://uploadtemp//" + file.getfilename ());
catch (Smartuploadexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}

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.