Android upload pictures, here I used the more popular Xutils framework, the framework can be implemented file upload, file download, image caching, etc., to be researched.
Here is the code uploaded by the android segment:
Xutils.jar Download
String uploadhost= "Http://192.168.1.100:8080/ReceiveImgFromAndroid/ReceiveImgServlet"; Server receive address Requestparams params=new requestparams ();p arams.addbodyparameter ("msg", "Upload image"); Params.addbodyparameter ("Img1", New File (FilePath)); FilePath is the picture address sendimgtoserver (Params,uploadpath) that the mobile phone obtains;
This is the way to upload files in the Xutils framework:
Public void Uploadmethod (final requestparams params,final String uploadhost) {http.send ( HttpRequest.HttpMethod.POST, Uploadhost, Params,new requestcallback<string> () {@Overridepublic void OnStart () { Upload start} @Overridepublic void onloading (long total, long Current,boolean isuploading) {//upload} @Overridepublic void Onsuccess (responseinfo<string> responseinfo) {//upload succeeded, the return value in this is the data returned by the server//using String result = Responseinfo.result get return value} @Overridepublic void OnFailure (httpexception error, String msg) {//upload failed}});}
On the top of the mobile phone to submit photos, next to write a server side.
The server side receives the mobile phone side to upload the photograph the method and receives the JSP interface to upload the photograph the way, is uses the Jspsmartupload_zh.jar package file. The simplest way to implement a servlet, in which call Smartupload class receive on the line, this also need to deal with the text to receive the garbled problem.
Here is the specific code:
Smartupload.jar Download
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android uses the xutils frame to upload photos (one or more) and text, the server receives photos and text (no garbled characters)