我从安卓代码中获取代码
下面是该代码的一部分。
protected String doInBackground(String... params) {
try {
String url = "http://192.168.1.21:8080/uploadimageserverside/upload.jsp";
int i = Integer.parseInt(params[0]);
Bitmap bitmap = decodeFile(map.get(i));
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
entity = new MultipartEntity();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
entity.addPart("user_id", new StringBody("199"));
entity.addPart("club_id", new StringBody("10"));
entity.addPart("club_image", new ByteArrayBody(data,"image/jpeg", params[1]));
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost,localContext);
sResponse = EntityUtils.getContentCharSet(response.getEntity());
System.out.println("sResponse : " + sResponse);
} catch (Exception e) {
if (dialog.isShowing())
dialog.dismiss();
Log.e(e.getClass().getName(), e.getMessage(), e);
}
return sResponse;
}
但我不知道如何在服务器端为java编写代码来读取文件和写入。请提前帮我谢谢。
您可以使用Jersey Framework来构建您的所有者Restful,如果您不知道如何使用后端,则需要安装一些工具来配置Restful,请参阅以下内容:
下载并安装:Apache Tomcat,Jersey-hello world示例
遵循本教程:
jersey rest web服务上传多个文件