最近我正在開發一個新項目,UTF-8
是必須的。我不知道我爲什麼要面對這個問題,但對我來說真的很陌生。我真的嘗試了我所知道的一切,但問題依然存在。無法解碼我的servlet中的西里爾字符串
我送一個JSON字符串到我的servlet和這裏是servlet部分:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
if (action.equals("startProcess")) {
final String data = request.getParameter("mainData");
URLDecoder.decode(data, "UTF-8");
System.out.println("DATA \n" + URLDecoder.decode(data, "UTF-8"));
JSONObject jsonObj = new JSONObject();
try {
JSONArray jsonArr = new JSONArray(URLDecoder.decode(data, "UTF-8"));
jsonObj.put("data", jsonArr);
JSONArray array = jsonObj.getJSONArray("data");
System.out.println("insertDtls \n" + jsonObj.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
的System.out.println("insertDtls \n" + jsonObj.toString());
回報:
這樣的結果:DATA [{"department":"1"},{"stampType":"кÑÑÐ³Ð»Ð°Ñ Ð¿ÐµÑаÑÑ"},{"headCompany":"да"},{"stampReason":"1"},{"textToPrint":"asd"},{"comments":"da"},{"other":"дÑÑгой"}]
我真的不知道在這裏做什麼。我確信我錯過了一些非常小的東西,但我無法發現它。有沒有可能讓這個字符串以某種方式進行雙重編碼?
是什麼角色呢?拉丁語還是其他語言?我認爲你不能用System.out打印大多數語言。 – ahmedalkaff
它是西里爾文。 – Slim
當你將它寫入響應而不是控制檯時,你會得到什麼? – ahmedalkaff