The encoding format in the URL is iso-8859-1, and the encoding format is only converted in Chinese iso-8859-1
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 (recommended use):
<%@ 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");
SSH environment JSP URL jump, with Chinese parameter garbled problem