JAVA 中URL链接中文参数乱码的若干处理方法,现在整理收录如下:
方法一:
http://xxx.do?ptname='我是中国人'
String strPtname = request.getParameter("ptname");
strPtname = new String(strPtname.getBytes("ISO-8859-1"), "UTF-8");
方法二:
//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').