DWR做反推时出现乱码,解决办法:
1. 在服务器反推前进行编码,代码如下:
// 进行编码, 防止乱码 String msg = "这该死的乱码啊"; try { msg = URLEncoder.encode(msg,"UTF-8"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); }2. 客户端接收的javascript方法里面解码,代码如下:
function showMessage(data) { var message = decodeURI(data.msg); // 解码 var text = dwr.util.getValue("info"); if (!!text) { dwr.util.setValue("info",text + "\n" + data.time + " " + message); } else { dwr.util.setValue("info",data.time + " " + message); } }