请各位看好问题再回答, 不要随便复制粘贴, 谢谢!
我已经设置了过滤器, 所有jsp页面也加了<%@ page language="java" contentType="text/html;charset=GBK" >
从jsp传参数, 在action里用request.getParameter("name")是正常的, 但是当我要跳转到另一个jsp时, 页面上取到的就是乱码.
action页面:
String name = request.getParameter("name"); // 得到'中国'
...
request.setAttribute("name", name );
return mapping.findForward("index");在index页面却得到乱码, 为什么?String wrongStr = (String)request.getAttribute("name");
String correctStr = new String(wrongStr.getBytes("ISO8859_1"),"GBK");
这样可以解决, 但是我的所有jsp页面都是用标签写的, 应该怎么解决啊?谁知道<c:out value="${name}"/>怎么样才不会乱码?

解决方案 »

  1.   

    两个JSP页面的编码和浏览器的编码要一致
    <%@ page language="java" contentType="text/html;charset=GBK" >
      

  2.   

    自己解决了, 谢谢各位!
    在action里加一句话, 转码!
    String name = request.getParameter("name"); // 得到'中国'
    name = new String(name .getBytes("iso-8859-1"),"GBK"); // 这句是关键
    ...
    request.setAttribute("name", name );
    return mapping.findForward("index");然后在index.jsp里<c:out value="${name}"/>取到就是正常中文了.
      

  3.   

    一般情况:
    name = new String(name .getBytes("iso-8859-1"),"UTF-8");