Session JSF/PrimeFaces/AJAX请求/WEbFilter和viewexpired异常
我正在开始一个新的JavaEE7项目,它需要PrimeFaces 5.0组件。JSF实现是Mojarra 2.2.0 设置初始项目依赖项后,我开始实现用户会话的处理,并优雅地处理viewExpiredException 第一步,我在web.xml中添加了下面的代码,这样在会话到期后,用户就可以重定向到相应的页面。好极了Session JSF/PrimeFaces/AJAX请求/WEbFilter和viewexpired异常,session,primefaces,jsf-2.2,glassfish-4,java-ee-7,Session,Primefaces,Jsf 2.2,Glassfish 4,Java Ee 7,我正在开始一个新的JavaEE7项目,它需要PrimeFaces 5.0组件。JSF实现是Mojarra 2.2.0 设置初始项目依赖项后,我开始实现用户会话的处理,并优雅地处理viewExpiredException 第一步,我在web.xml中添加了下面的代码,这样在会话到期后,用户就可以重定向到相应的页面。好极了 <error-page> <exception-type>javax.faces.application.ViewExpiredException
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/exception/sessionexpired.xhtml</location>
</error-page>
<factory>
<exception-handler-factory>
org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory
</exception-handler-factory>
</factory>
之后,我优雅地处理的viewExpiredException消失了(没关系,我将在Filter中处理会话),但会话过期后的AJAX请求不再得到处理。这是否意味着,当我实现WebFilter时,我必须处理其中的所有请求(还要检测AJAX调用并执行适当的重定向),并且我可以放弃web.xml和faces-config.xml配置来处理异常
蒂亚,
D00de.嗯,是的-一旦会话过期,就无法处理任何内容。适当地重定向您的用户以重新验证。这就是我在WebFilter中所做的,他们会被重定向。现在,我还在我的WebFilter中手动实现了ajax/部分请求检测。问题是,如果最后我需要处理WebFilter中的所有内容,为什么我需要viewexpired处理程序?
@WebFilter("/*")
public class AuthorizationFilter implements Filter {
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws ServletException, IOException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession(false);
User user = (session != null) ? (User) session.getAttribute("user") : null;
String loginURL = request.getContextPath() + "/login.xhtml";
boolean loginRequest = request.getRequestURI().startsWith(loginURL);
boolean resourceRequest = request.getRequestURI().startsWith(request.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER);
if (user != null || loginRequest || resourceRequest) {
chain.doFilter(request, response);
} else {
response.sendRedirect(loginURL);
}
}