还是JSP中request转化乱码问题
A.jsp向B.jsp传递参数 (A.jsp和B.jsp都是pageEncoding="utf-8")
A.jsp: href="b.jsp?r_id=<%=borr.getid()%>&outime=<%=borr.getoutime()%>&backtime=<%=borr.getbacktime()%>&b_id=<%=borr.getb_id()%>&user_id=<%=borr.getuser_id()%>&class_id=<%=borr.getclass_id()%>&class_name=<%=borr.getclass_name()%>&reserved=<%=borr.getreserved()%>&borrowed=<%=borr.getborrowed()%>&reserved=<%=borr.getreserved()%>&reborrowed=<%=borr.getreborrowed()%>&should=<%=borr.getshould()%>"
B.jsp: <%String class_name= new String(request.getParameter("class_name").getBytes("ISO-8859-1"),"utf-8");
System.out.println(class_name);%>
正确结果为 小型车
输出结果很搞笑:小型??reserverd=0 (reserved=0 表示未被预定);
既乱码又跨越读值,连&都没用了
郁闷死 以前那个系统一切运行正常 刚换了一个纯净版本的XP就成这样了,坐等高手解答
------解决方案--------------------A.jsp向B.jsp传递参数 (A.jsp和B.jsp都是pageEncoding="utf-8")
A.jsp: href="b.jsp?r_id=<%=borr.getid()%>&outime=<%=borr.getoutime()%>&backtime=<%=borr.getbacktime()%>&b_id=<%=borr.getb_id()%>&user_id=<%=borr.getuser_id()%>&class_id=<%=borr.getclass_id()%>&class_name=<%=borr.getclass_name()%>&reserved=<%=borr.getreserved()%>&borrowed=<%=borr.getborrowed()%>&reserved=<%=borr.getreserved()%>&reborrowed=<%=borr.getreborrowed()%>&should=<%=borr.getshould()%>"
B.jsp: <%String class_name= new String(request.getParameter("class_name").getBytes("ISO-8859-1"),"utf-8");
修改为:B.jsp: <%String class_name= new String(request.getParameter("class_name");
System.out.println(class_name);%>
------解决方案--------------------
------解决方案--------------------使用URLEncoder URLDecoder 试下,你项目的编码是不是也是utf-8的,或者tomcat的server.xml配置文件中是不是加了URIEncoding="UTF-8" 加了这句有时候jsp即使是统一编码也会出现乱码的,
还有,看下你jsp页面属性是不是也是utf-8的,页面属性要utf-8 pageEncoding 也要utf-8
------解决方案--------------------http://blog.csdn.net/lgm277531070/archive/2011/01/12/6132941.aspx
看下这个,我以前也遇见跟你一样的问题
上面说错了,有时候单加URIEncoding="UTF-8" 反而会出现乱码,加了这句后同时要给传的参数使用URLEncoder 和URLDecoder 进行编码解码....
------解决方案--------------------可尝试:
1 B.jsp页面从request取值前先 request.setCharacterEncoding("UTF-8");一下
2 在tomcat的server.xml中修改
<Connector
port="80" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true"
URIEncoding="UTF-8"/>
3 可以写个中文过滤器