客户端用js函数encodeURI()对中文字符进行两次编码,服务器端采用URLDecoder类对客户端传输过来的中文字符进行UTF-8格式的解码。示例:
$.ajax({
type: "post",
url: "createNewGroup.action",
data:"name="+encodeURI(encodeURI("张三")),
success: function(msg){
alert(msg);
}
});服务器端代码:
String name= request.getParameter("name");
name = URLDecoder.decode(URLDecoder.decode(name, "UTF-8"),"UTF-8");
[color=red]如果 encodeURI 进行了两次编码,则后台就要两次,如果encodeURI值进行了一次编码,则后台只需要一次。 网上是说 js进行两次encodeURI编码,但是后台只一次,我这里试过没有用,一定两次解码。 [/color]
6207



被折叠的 条评论
为什么被折叠?



