0

我正在编写我的第一个javax.servlet.Filterimpl 并尝试编写doFilter方法的一部分,以防止请求在链中进一步传播:

@Override
public void doFilter(ServletRequest request, ServletResponse response)
        FilterChain chain) throws IOException, ServletException {
    // Check for some stuff in the request...
    boolean passesInspection = inspect(request);

    if(!passesInspection)
        // How do I prevent the request from going any further?
        // I don't want it even getting to the servlet at this point!
}

我如何“阻止”请求甚至将其发送到侦听 servlet?提前致谢。

4

1 回答 1

4

干脆不叫chain.doFilter()doFilter()呼叫是呼叫的进展。不要调用它,处理就会停止。然而,这不是一个好的设计。你至少需要通知来电者

于 2013-02-17T21:42:22.950 回答