小编yeh*_*ria的帖子

android将utf8内容发送给servlet

我正在使用Android将英语和阿拉伯语内容发送到Servlet,但数据会发送到服务器.怎么解决?这是Android中的代码:

StringEntity se = new StringEntity(gsonString);
se.setContentType("text/json;charset=UTF-8");
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json;charset=UTF-8"));
HttpPost httpRequest = new HttpPost(methodURL);
httpRequest.setEntity(se);
HttpResponse response = httpClient.execute(httpRequest,localContext);
Run Code Online (Sandbox Code Playgroud)

Servlet代码

request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream()));
    String line = in.readLine();
    String gsonString = line;
    while (line != null) {
        gsonString += line;
        line = in.readLine();
    }
Run Code Online (Sandbox Code Playgroud)

有什么建议 ?

java android hibernate servlets web

1
推荐指数
1
解决办法
4723
查看次数

标签 统计

android ×1

hibernate ×1

java ×1

servlets ×1

web ×1