对于get方式,请求参数中存在中文,可以使用下面的方法进行处理:
来自页面的一个get请求:
window.location.href = getContextPath()+"/manage/user/detail?name="+encodeURI(encodeURI("小明"));
在js 里通过encodeURI(encodeURI("小明"))将所携带中文参数编译
服务器端:
String name = request.getParameter("name");
orgname = URLDecoder.decode(name,"UTF-8");
在控制器里通过 URLDecoder.decode(name,"UTF-8")编译转换成中文
编译用encodeURI(encodeURI("小明")),解码用decodeURI(decodeURI("小明"));
也可以传递变量
var name="小明"
var nameCode=encodeURI(encodeURI(name));
window.location.href = getContextPath()+"/manage/user/detail?name="+nameCode;
网友评论