珠海建设企业网站,网络维护管理,临清建设网站,泰安贴吧百度贴吧对于类似的功能(从装载Android的照片与Servlet)#xff0c;这里的Android客户端的代码#xff0c;我使用(在这里发帖而稍加编辑)#xff1a;URI uri URI.create(// path to file);MultipartEntity entity new MultipartEntity(HttpMultipartMode.STRICT);// several key-v…对于类似的功能(从装载Android的照片与Servlet)这里的Android客户端的代码我使用(在这里发帖而稍加编辑)URI uri URI.create(// path to file);MultipartEntity entity new MultipartEntity(HttpMultipartMode.STRICT);// several key-value pairs to describe the data, one should be filenameentity.addPart(key, new StringBody(value));File inputFile new File(photoUri.getPath());// optionally reduces the size of the photo (you can replace with FileInputStream)InputStream photoInput getSizedPhotoInputStream(photoUri);entity.addPart(CONTENT, new InputStreamBody(photoInput, inputFile.getName()));HttpClient httpclient new DefaultHttpClient();HttpPost httppost new HttpPost(uri);HttpContext localContext new BasicHttpContext();httppost.setEntity(entity);HttpResponse response httpclient.execute(httppost, localContext);和这里的代码来接受它。首先一定要标记您的servlet类为支持多消息MultipartConfigpublic class PhotosServlet extends HttpServlet然后身体的相关部分HttpEntity entity new InputStreamEntity(request.getPart(CONTENT).getInputStream(), contentLength);InputStream inputFile entity.getContent();// string extension comes from one of the key-value pairsString extension request.getParameter(//filename key);// first write file to a fileFile images new File(getServletContext().getRealPath(images));File filePath File.createTempFile(user, extension, images);writeInputDataToOutputFile(inputFile, filePath); // just copy input stream to output streamString path filePath.getPath();logger.debug(Wrote new file, filename: path);希望它能帮助。