web.xml文件
<filter>
<filter-name></filter-name>
<filter-class></filter-class>
</filter>
<filter-mapping>
<filter-name> </filter-name>
<url-pattern>/*</url-pattern><!--/*指所有的请求都可以-->
</filter-mapping>
实现类.Class 继承Filter
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
// TODO Auto-generated method stub
System.out.println("doFilter-------------------");
//检查放行
chain.doFilter( request, response);
}
实现类.Class
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
// TODO Auto-generated method stub
System.out.println("doFilter-------------------");
//凡是经过Filter的字符格式都为UTF-8
HttpServletRequest req=(HttpServletRequest)request;
req.setCharacterEncoding("UTF-8");
//检查放行
chain.doFilter( request, response);
}