应该执行重定向的过滤器:
@WebFilter(filterName = "TestFilter", urlPatterns = {"/WEB-INF/jaas/*"}, dispatcherTypes = {DispatcherType.FORWARD})
public class TestFilter implements Filter {
public TestFilter() {}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = ((HttpServletResponse) servletResponse);
HttpServletRequest request = (HttpServletRequest) servletRequest;
response.sendRedirect(request.getContextPath() + "/Home.xhtml");
//chain.doFilter(servletRequest, servletResponse);
}
//...
}
该位置只有一个XHTML文件映射到URL模式。
托管bean转发到上面的过滤器。
@Named
@ViewScoped
public class TestBean implements Serializable {
private static final long serialVersionUID = 1L;
public TestBean() {}
public void action() throws IOException {
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
context.dispatch("/WEB-INF/jaas/jaas.xhtml");
}
}
最后,action()
方法绑定到<p:commandButton>
。
<h:form>
<p:commandButton value="Submit" ajax="false" actionListener="#{testBean.action}"/>
</h:form>
仅当与ajax
关联的<p:commandButton>
设置为false
时,所述过滤器才会重定向到所述资源,如上所示。
如果是Ajaxical请求,那么应该由过滤器执行的重定向不会发生(没有错误)。
当以上述方式将Ajaxical请求发送到过滤器时,是否可以执行重定向?