J2EE中文乱码

来源:互联网 发布:阿里云金牌合作伙伴 编辑:程序博客网 时间:2024/05/10 08:52

http://www.cnblogs.com/rollenholt/archive/2012/12/26/2833921.html

 

1.过滤器

public class CharsetFilter implements Filter{private String encoding;public void init(FilterConfig filterconfig) throws ServletException {// TODO Auto-generated method stubencoding = "utf-8";}public void doFilter(ServletRequest servletrequest,ServletResponse servletresponse, FilterChain filterchain)throws IOException, ServletException {// TODO Auto-generated method stubservletrequest.setCharacterEncoding(encoding);filterchain.doFilter(servletrequest, servletresponse);}public void destroy() {// TODO Auto-generated method stubencoding = null;}}


2.web.xml配置

<filter><filter-name>charset</filter-name><filter-class>com.test.ticket.web.filter.CharsetFilter</filter-class></filter><filter-mapping><filter-name>charset</filter-name><url-pattern>/*</url-pattern></filter-mapping>


 

原创粉丝点击