javascript url 传递参数中文乱码问题解决方案

方案一

html页面:

function testOne() {

   var url =  "testTwo.action?expr="+你好;

   window.location.href = encodeURI(url);

}

 

后台java代码:

String expr = new String(request.getParameter("expr").getBytes("ISO-8859-1"),"UTF-8");  

 

方案二

html页面:

function testTwo() {

  var url =  "testTwo.action?expr="+你好;

  window.location.href= encodeURI(encodeURI(url)); 

}

 

后台java代码:

String expr = java.net.URLDecoder.decode(lrequest.getParameter("expr") , "UTF-8");

 

----------------------------------------------------------------------------------------------------------------------------------

如果用的是weblogic服务器的话,用方案二是可以解决的(我的weblogic的版本是weblogic 9.2的),方案一解决不了。

如果是tomcat服务器的话,这两个方案都可以;也可以在传递参数不处理,后台用

String expr = new String(request.getParameter("expr").getBytes("ISO-8859-1"),"UTF-8");  

也是可以的。

你可能感兴趣的:(JavaScript,java,tomcat,.net,weblogic)