这是过滤器的类
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import java.io.IOException;/**
 *
 * Date: 2005-9-19
 * Time: 17:33:36
 *  @author Duzk
 */
public class MyFilter extends HttpServlet implements Filter {
    private FilterConfig filterConfig;
    //Handle the passed-in FilterConfig
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }    //Process the request/response pair
    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain filterChain) {        try {
            request.setCharacterEncoding("GBK");
            filterChain.doFilter(request, response);        } catch (ServletException sx) {
            filterConfig.getServletContext().log(sx.getMessage());
        } catch (IOException iox) {
            filterConfig.getServletContext().log(iox.getMessage());
        }
    }    //Clean up resources
    public void destroy() {
    }
}然后在web.xml里加上这段
<filter>
    <filter-name>MyFilter</filter-name>
    <filter-class>类路径.MyFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>MyFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>这个是就用来过滤的类啦,,
web.xml里加那段代码,,但我一搜Tomcat,搜出差不多十个web.xml来,,但具体是对哪个web.xml修改呢??
我试过全部都修改,,结果连tomcat连启动不到了..

解决方案 »

  1.   

    webapps\你的站点目录\\WEB-INF\web.xml
      

  2.   

    D:\Program Files\Tomcat 5.5\webapps\ROOT\WEB-INF\classes
    <filter-class>类路径.MyFilter</filter-class>裏的路徑我寫以上那句,,請問對嗎??
    但為什麽在啟動tomcat時出現嚴重錯誤,,
      

  3.   

    webapps\你的站点目录\WEB-INF\web.xml就是这个了
    如果你的MyFilter放在WEB-INF\classes下
    就这样写<filter-class>MyFilter</filter-class>
    不过建议楼主把MyFilter加个包,以避免以后不必要的麻烦