两个页面跳转 url传中文 非法字符及乱码

来源:互联网 发布:网络借贷平台合法的吗 编辑:程序博客网 时间:2024/05/22 04:59

弄了两个小时终于解决了!!!


问题:在一页面的url传中文,从一页面跳转到二页面,在二页面中得到url中的中文乱码!


解决办法:在一页面的url用encodeURIComponent转两次码(解决非法字符和中文乱码),

                            window.location.href="edit.jsp?content="+encodeURIComponent(encodeURIComponent("我是"));   



                  在二页面中

        <%
          String content=request.getParameter("content");
          content=URLDecoder.decode(content,"utf-8");//对中文参数进行解码
         %>
        <textarea  style="width:1050;height:285px;resize:none;"><%=content %></textarea> </td> 



textarea中值便为:我是

0 0
原创粉丝点击