凤凰求蛊
弄过滤器,要实现filter接口主要是用过滤器处理中文编码,至于要用来做什么,再自己写比如权限控制,登录验证,之类//下面这是一个类。。。。import java.io.IOException;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class EncodingFilter implements Filter {public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {request.setCharacterEncoding("GBK");//处理编码response.setCharacterEncoding("GBK");//处理编码chain.doFilter(request, response);//让过滤器执行下一个请求}public void destroy() {}public void init(FilterConfig arg0) throws ServletException {}}//下面这个是在web.xml下的配置<filter><filter-name>encoding</filter-name><filter-class>刚刚创建的那个实现filter接口的类的位置例如:com.temp.filter.EncodingFilter</filter-class></filter><filter-mapping><filter-name>encoding</filter-name><url-pattern>*.jsp这个是以jsp为后缀的文件都拦截下来</url-pattern></filter-mapping>可以写多个的<filter-mapping>来配置你所要拦截的东西