我在 web.xml 中定义了一个过滤器,如下所示:-
<filter-mapping>
<filter-name>AuthenticationFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<filter>
<display-name>AuthenticationFilter</display-name>
<filter-name>AuthenticationFilter</filter-name>
<filter-class>com.filters.AuthenticationFilter</filter-class>
</filter>
在过滤器中我有以下代码: -
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
// place your code here
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse hres = (HttpServletResponse) response;
String pathInfo = httpRequest.getRequestURI().trim();
System.out.println(pathInfo);
// Do not process any non-jsp files or LogIn.jsp ! pathInfo.endsWith("jsf") ||
if (pathInfo.endsWith("RegistrationForm.jsf") || pathInfo.endsWith("Login.jsf")) {
chain.doFilter(request, response);
return;
}
// pass the request along the filter chain
User user = (User) httpRequest.getSession().getAttribute("USER_IN_SESSION");
if(user==null)
hres.sendRedirect("Login.jsf");
else {
chain.doFilter(request, response);
}
}
问题是,如果我使用 Topic.jsp 调用应用程序,它会像这样循环:-
Topic.jsp
LogIn.jsf
Login.jsp
Login.jsf
Login.jsp
...
我发现问题是映射中的 FORWARD 。如果删除此条目,它可以工作
<dispatcher>FORWARD</dispatcher>
请帮我解决这个无限循环交替.jsp 和 .jsf的难题:)