jsp页面
<%@ page contentType="text/html; charset=GBK" %>JavaScript
xmlHttpRequest.send("province="+sheng);
到action里接收到参数System.out.println(province);
newProvince = new String(province.getBytes("iso-8859-1"),
"GBK");都乱码啊,怎么办啊???非常着急啊
<%@ page contentType="text/html; charset=GBK" %>JavaScript
xmlHttpRequest.send("province="+sheng);
到action里接收到参数System.out.println(province);
newProvince = new String(province.getBytes("iso-8859-1"),
"GBK");都乱码啊,怎么办啊???非常着急啊
"GBK");也乱码啊!我只求能正确显示成中文,该转成什么码啊??
如果是那就要先把sheng在页面用js的encodeURIComponent编码一下,
我好像以前也遇到过,祝你成功!
request.setCharaterEncoding("GBK");//方法记没记错,忘了
把ajax封装一下,在header加上一个标记,如IS_AJAX "TRUE"然后在服务器端加一个filter,或叫CodeFilter.
characterEncoding=request.getCharacterEncoding();
if(characterEncoding==null){
if(request.header['IS_AJAX']!=null){
request.setCharacterEncoding("utf-8");
}else{
request.setCharacterEncoding("gbk");
}
}在项目我一般这样用。用jquery的ajax,不过我看了下源码,在发送之前都会用encodeURIComponent包装一下的。如果你不是用jquery,可能需要包装一下。