发送图像用Java servlet中如何获得servlet的图像 [英] Sending a image to servlet in java how to get the image in servlet

查看:105
本文介绍了发送图像用Java servlet中如何获得servlet的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我送从Android手机图像服务器这是我使用的的HttpClient和HttpPost,这和ByteArrayBody发送之前存储图像的servlet。

我如何从Servlet的POST请求提取图像。

下面是我的code发送POST请求

 字符串postURL = //服务器的URL;HttpClient的HttpClient的=新DefaultHttpClient();
HttpPost postRequest =新HttpPost(postURL);ByteArrayBody BAB =新ByteArrayBody(imageBytesfile_name_ignored);
MultipartEntity reqEntity =新MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart(来源,BAB);
postRequest.setEntity(reqEntity);HTT presponse响应= httpClient.execute(postRequest);


解决方案

使用类似通用FileUpload

有在Apache文档的例子,所有网站。

I am sending a image from android phone to server which is a servlet I am using the HttpClient and HttpPost for this and ByteArrayBody for storing the image before sending.

how do i extract the image from the post request in Servlet.

Here is my code for sending the post request

String postURL = //server url;

HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(postURL);

ByteArrayBody bab = new ByteArrayBody(imageBytes,"file_name_ignored");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("source", bab);
postRequest.setEntity(reqEntity);

HttpResponse response = httpClient.execute(postRequest);

解决方案

Use something like commons fileupload.

There are examples in the Apache docs, and all over the web.

这篇关于发送图像用Java servlet中如何获得servlet的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆