Android image upload Server side (i)

Source: Internet
Author: User

Directly on the browser-side upload.jsp code (for test server side)

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" Utf-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" ><form action= "${pagecontext.request.contextpath}/upload.do" method= "post" enctype= "Multipart/form-data" > Note Enctype= "Multipart/form-data" (complex data submission) and {Pagecontext.request.contextpath}/upload.do Engineering access path

There is a uniform use of the character set Utf-8 careful Chinese garbled.

2. Server side, using Commons-fileupload for file upload, still using servlet

commons-fileupload-1.3.1.jar+ Commons-io-2.4.jar (I appear compatible error)

The code is as follows

protected void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException { Request.setcharacterencoding ("Utf-8"); Response.setcharacterencoding ("Utf-8");//Determine if complex form submission Boolean ismutipart=    Servletfileupload.ismultipartcontent (Request);          if (Ismutipart) {//configure Cache factory Diskfileitemfactory factory=new diskfileitemfactory ();     Set Cache size Factory.setsizethreshold (1024*1024*2);     File Temp=new file ("D:\\temp");     if (!temp.exists ()) {Temp.mkdir ();}          Factory.setrepository (temp);    Servletfileupload upload=new servletfileupload (Factory);     Upload.setheaderencoding ("Utf-8");     Upload.setfilesizemax (1024*1024*5);          Upload.setsizemax (1024*1024*6); Gets the collection of commits try {list<fileitem>items=upload.parserequest (Request), if (Items!=null) {for (Fileitem item:items) {if (Item.isformfield ()) {//General Data System.out.println (Item.getfieldname ()); System.out.println (item.getstring ("Utf-8"));} else {String PATHSTRING=ITEM.GEtname (), if (pathstring.contains ("\ \")) {int index=pathstring.lastindexof ("\ \");p athstring=pathstring.substring ( index+1);} System.out.println (pathstring);//Complex file try {item.write (new file ("d:\\" +pathstring)), Response.getwriter (). Write (" Upload success! ");} catch (Exception e) {e.printstacktrace (); Response.getwriter (). Write ("Upload fail.");}}}}               catch (Fileuploadexception e) {//TODO auto-generated catch Blocke.printstacktrace ();}    } else {return;} }

Portal: [rar file] andriod, iOS server-side code file upload



Android image upload Server side (i)

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.