struts解决乱码

来源:互联网 发布:js dom style属性 编辑:程序博客网 时间:2024/06/05 16:44

一:1.前台请求传到后台,中文乱码问题:

比如URL传参:

将中文参数转码:

var name=encodeURI(encodeURI("百度"));

window.location.href="www.baidu.com/test.action?name="+百度+"&age="+age;

将参数先转两次编码


2.后台接收参数:

try{

String  name=encodeURI("name","utf-8");

}catch (UnsupportedEncodingException e) {

}

将编码转成utf-8的格式


二:

后台传递参数到前台

比如使用response传递json数据:获取response时转码

response.setContentType("text/html;charset=UTF-8");
        response.setCharacterEncoding("utf-8");

三:注意:

传递参数,最好使用$.post传参或者使用表单传参

若使用struts框架,做好配置一个struts.properties




原创粉丝点击