myeclipse jsp post方式提交中文乱码解决办法

import java.io.*; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; public class SetCharacterEncodingFilter implements Filter { protected String encoding = null; public void destroy() { this.encoding = null; } public void init(FilterConfig filterConfig) throws ServletException { this.encoding = filterConfig.getInitParameter("encoding"); } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding(encoding); response.setContentType("text/html;charset=" + encoding); chain.doFilter(request, response); } }

 

web.xml配置如下:

<filter> <filter-name>SetCharacterEncodingFilter</filter-name> <filter-class> com.smzbtv.filter.SetCharacterEncodingFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>gb2312</param-value> </init-param> </filter> <filter-mapping> <filter-name>SetCharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>


注意: 以上web.xml里对转码的配置必须放在Struts2配置前面

你可能感兴趣的:(jsp,MyEclipse,struts,filter,import,encoding)