http://www.blogjava.net/jerry-zhaoj/archive/2009/07/16/286993.html turn
Java URL link The processing method of the Chinese parameter garbled in Java URL link Chinese parameter garbled processing method in Java URL link Chinese parameter garbled
In the URL to ask the parameter garbled, we have been in the "solution Ajax submitted Chinese, URL Chinese parameters after the problem of garbled solution" one of the solutions, the net is: http://www.javaly.cn/javahome/java/ Content.detail/%e8%a7%a3%e5%86%b3ajax%e6%8f%90%e4%ba%a4%e4%b8%ad%e6%96%87%e3%80%81url%e4%b8%ad%e6%96%87%e5%8f% 82%e6%95%b0%e4%bc%a0%e9%80%92%e5%90%8e%e7%9a%84%e4%b9%b1%e7%a0%81%e9%97%ae%e9%a2%98%e7%9a%84%e8%a7%a3%e5%86%b3 %e5%8a%9e%e6%b3%95/fdc1ed6c22069c56012282a321ed0465.faces
Today, we find other solutions.
Method One:
Http://xxx.do?ptname= ' I am Chinese '
String strptname = Request.getparameter ("Ptname");
Strptname = new String (strptname.getbytes ("iso-8859-1"), "UTF-8");
Method Two:
<%@ page contenttype= "text/html;charset=gb2312"%>
<a href= "Ds.jsp?url=<%=java.net.urlencoder.encode (" coded is Here "," GB2312 ")%>" > click here </a>
<%
Request.setcharacterencoding ("GBK");
if (request.getparameter ("url")!=null)
{
Str=request.getparameter ("url");
Str=java.net.urldecoder.decode (str, "GB2312");
Str=new String (str.getbytes ("iso-8859-1"));
Out.print (str);
}
%>
==================================
public string chinatostring (String str)
{
String S=str;
Try
{
Byte tempb[]=s.getbytes ("Iso-8859-1");
S=new String (TEMPB);
return s;
}
catch (Exception e)
{
return s;
}
}
====================================================
function UrlEncode (SSTR)
{
Return Escape (SSTR).
Replace (/"+/g, '%2b ').
Replace (/""/g, '%22 ').
Replace (/"'/g, '%27 ').
Replace (/"//g, '%2f ');
}
Method Three:
If you use Jstl, you can write your own El function, call Urlencoder.encode to encode.
ie defaults to the URL after the parameter is not encoded sent, but Tomat by default is to press iso8859-1 for URL decoding, so the above error occurs. The good practice is to:
1, in the URL parameters to ensure that the UTF-8 code, the method can be used with the JS function encodeURI (), or call the custom El function;
2, set Server.xml Connector familiar with uriencoding= "UTF-8", to ensure that the decoding format and encoding format are unified;
Method Four:
<script>
for (Var i=0;i<document.links.length;i++) {
Document.links[i].href=encodeuri (DOCUMENT.LINKS[I].HREF);
}
</script>
In action, String s=request.getparameter ("s");
S=new String (s.getbytes ("iso-8859-1"), "GBK");
Java URL Chinese parameter garbled problem