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 pathThere 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)