【发布时间】:2011-03-25 19:42:12
【问题描述】:
我需要转发我的请求(到 jsp,但我认为这无关紧要)来自 http.Filter 如果原始请求的 URI 通过了我的过滤器运行的一些验证。
我找到了这个page that faced similar task
我还需要弄清楚以下几点:
如何在
doFilter()方法中获取ServletContext(以便调用转发API)getServletContext()不被识别我必须在转发之前、转发之后还是根本不需要
call chain.doFilter()? 此外,如果我的验证通过或仅在验证失败时(因为在这种情况下我不会继续转发我的页面),我是否必须致电chain.doFilter()?
这个问题居然继续this thread, 更明显的是,代码可能是这样的:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if (request instanceof HttpServletRequest) {
HttpServletRequest httpServletRequest = ((HttpServletRequest)request);
String requestURI = httpServletRequest.getRequestURI();
String contextPath = httpServletRequest.getContextPath();
if (<this is my implementation of the validation of this filter>){
getServletContext().getRequestDispatcher(
"MySpecific.jsp").forward(request,response);
}
}
chain.doFilter(request,response);
}
【问题讨论】:
标签: java jakarta-ee filter