JAVA中URL鏈接中文參數亂碼處理方法
IE缺省對URL後麵的參數是不編碼發送的,但是tomat缺省是按ISO8859-1來進行URL編碼的,因此才會出錯。方法一
https://xxx.do?ptname=中文參數
String strPtname = request.getParameter("ptname");
strPtname = new String(strPtname.getBytes("ISO-8859-1"), "UTF-8");
方法二
<%@ page contentType="text/html;charset=gb2312" %>
<a href="ds.jsp?url=<%=java.net.URLEncoder.encode("編碼的是這裏","GB2312")%>">點擊這裏</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);
}
%>
方法三
Tomcat中設置server.xml中的Connector熟悉URIEncoding="UTF-8",確保解碼格式與編碼格式統一。
節選自:https://blog.csdn.net/hudon/article/details/2051332
最後更新:2017-04-04 07:36:11