关于对jsp中Url含中文字符的编码处理
<P> 有一段url="/app/index/index.jsp?userName='测试'";在传入到jsp页面后。</P><P> 用 <% String userName=request.getParameter("userName"); %></P>
<P> 还是用(struts spring jquery 环境下) ${param.userName},获取得到都是中文乱码了。所以需要对url进行先编码后再使用。如JS处理:</P>
<P> var re = new RegExp('[\u4e00-\u9fa5]', "ig");//捕获中文,编码<BR> var chs=url.match(re);<BR> if(chs){<BR> for(var i=0;i<chs.length;i++){<BR> url=url.replace(chs, encodeURIComponent(chs));<BR> }<BR> }<BR></P>
<DIV>这样把url中中文先转码UTF-8再使用。则后面得到jsp中页面的值才正确显示。</DIV>
<DIV></DIV>
页:
[1]