js的url 中文乱码问题

如果需求一定要在js的url中传递中文的话,必须对该中文进行处理。

例如从 A.jsp --> B.jsp

在JS里对中文参数进行两次转码

-------------------A.jsp中:

 var name = encodeURI(encodeURI(data.msg[0].Bt));
$("#dwxxbt").html("<a class='dwxx' href='<%=url%>/pages/zph/zphGdcjqy.jsp?zphzj=<%=zphzj%>&zphBt="+name+"'>查看参加企业>></a>");


-------------------B.jsp中:

 <% 
        String path = request.getContextPath(); 
        String url = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
        String zphBt = (String)request.getParameter("zphBt");
        zphBt = java.net.URLDecoder.decode(zphBt,"utf-8");//decode string to chinese word

%>

<%=zphBt%>就可以正常显示了。

猜你喜欢

转载自563432906.iteye.com/blog/2278570