java和过滤器-如何运行?

scyqe7ek  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(231)

我有一个过滤器:

@WebFilter(urlPatterns = "/Mvc02")
public class Filter02 implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        some code...
    }

    public void init(FilterConfig config) throws ServletException {

    }
}

和servlet:

@WebServlet(name = "Mvc02", urlPatterns = "/Mvc02")
public class Mvc02 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        some code...
    }
}

当我进入浏览器并键入http://localhost:8080/servletjee\u war\u/mvc02它给了我一个servlet。它不应该先给我过滤器吗?如何运行过滤器?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题