session中保存中文乱码问题
我在控制层保存了一个session.setAttribute("haha","哈哈");
然后我在变现层使用EL表达式:${sessionScope.haha}取出来的汉字是乱码,其他的JSP功能正常显示,就session取出来的汉字是乱码。思路是什么呢?如何一次性解决?因为这样的有好几处,我不想string来转码,很麻烦啊
多谢
------解决方案--------------------自己写一个过滤器:
public class DoFilter implements Filter
{
public void destroy() {
}
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws
IOException,
ServletException {
arg1.setCharacterEncoding("GBK");
arg2.doFilter(arg0, arg1);
}
public void init(FilterConfig arg0) throws ServletException {
}
}
在web。xml中配置:
<!-- 过滤器 -->
<filter>
<filter-name>encodingFilter </filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter </filter-class>
<init-param>
<param-name>encoding </param-name>
<param-value>UTF-8 </param-value>
</init-param>
<init-param>
<param-name>forceEncoding </param-name>
<param-value>true </param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter </filter-name>
<url-pattern>*.jsp </url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>encodingFilter </filter-name>
<url-pattern>*.do </url-pattern>
</filter-mapping>