解决数据库乱码

EncodingFilter:

 

 

public class EncodingFilter implements Filter {

 public void destroy() {
  
  
 }

 public void doFilter(ServletRequest req, ServletResponse resp,
   FilterChain chain) throws IOException, ServletException {
  
  req.setCharacterEncoding("UTF-8");
  
  resp.setCharacterEncoding("UTF-8");
  
  chain.doFilter(req,resp);
  
 }

 public void init(FilterConfig arg0) throws ServletException {
  
  
 }

 

 

 

 

 

 

WEB.XML:

 

 

 

 
  <!--   编码格式过滤器  -->
 <filter>
  <filter-name>EncodingFilter</filter-name>
  <filter-class>ectss.util.EncodingFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>EncodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

你可能感兴趣的:(数据库,filter,Class)