Quantcast
Channel: 質問!ITmedia 新着質問(Java/253)
Viewing all articles
Browse latest Browse all 2439

multipart形式で送信時の日本語の文字化け

$
0
0
android端末から日本語の文字列と画像をmultipart形式で送信し、サーブレット側で 取得するプログラムを作成したいのですが、日本語が文字化けしてしまいます。 android側のソースコード DefaultHttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(URL); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName("UTF-8" )); try { entity.addPart("ADDRESS", new StringBody("address")); File file = new File(Path); entity.addPart("IMAGE", new FileBody(file.getAbsoluteFile())); post.setEntity(entity); HttpResponse response = client.execute(post); }catch (IOException e) { Log.w("Curry", e.getLocalizedMessage(), e); }catch (NullPointerException e) { e.printStackTrace(); } サーブレット側のソースコード public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { memoryFileItemFactory factory = new memoryFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List list = upload.parseRequest(req); Iterator iterator = list.iterator(); while (iterator.hasNext()) { FileItem item = (FileItem) iterator.next(); if (!(item.isFormField())) { //送信された画像データに対する処理 } if((item.isFormField())){ //送信された日本語文字に対する処理 String address=item.getString(); address=new String(address.getBytes("iso-8859-1"), "UTF-8"); } } } 上記の、送信された日本語文字の処理のaddressを出力してみると、 日本語の部分だけ????になってしまいます。どうすれば日本語文字を取得できるのでしょうか。 どなたか回答お願いします。

Viewing all articles
Browse latest Browse all 2439

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>