URL参数中文乱码解决(参数中间经过两次使用)

阅读更多
在配合CRM做二期项目时,在网点查询功能实现的时候,由于使用的get方式传递中文参数,导致新打开的jsp 获取参数为乱码。
URL中contactAddr,shopSite均为中文参数
var url = path+"/service/depponDept/depponDept_search_visitframe.jsp?custAddress="
				+ encodeURI(encodeURI(contactAddr)) + "&shopSite=" + encodeURI(encodeURI(shopSite));


jsp上获取参数Java代码
String custAddress = StringUtil.killNull(request.getParameter("custAddress"));
String shopSite = StringUtil.killNull(request.getParameter("shopSite"));
custAddress=URLDecoder.decode(custAddress,"UTF-8");
shopSite = URLDecoder.decode(shopSite,"UTF-8");

但是这两个参数还要第二次在URL中使用:
&shopSite=<%=URLEncoder.encode(URLEncoder.encode(shopSite,"UTF-8"),"UTF-8")%>">

最终使用URL中的这两个参数处理代码为:
String custAddress = StringUtil.killNull(request.getParameter("custAddress"));
String shopSite = StringUtil.killNull(request.getParameter("shopSite"));
custAddress=URLDecoder.decode(custAddress,"UTF-8");
shopSite=URLDecoder.decode(shopSite,"UTF-8"
);

这就是URL中文参数两次处理过程。

你可能感兴趣的:(URL参数中文乱码解决(参数中间经过两次使用))