我有两个用户。公开和登录。当用户是公共和会话超时时,我只是传递请求,如
Cookie userCookie = getCookie(httpServletRequest, "userCookie");
if (userCookie != null) {
String value = userCookie.getValue();
if (value.equalsIgnoreCase("normal")) {
session.setAttribute("logedin", "0");
filterChain.doFilter(httpServletRequest, httpServletResponse);
} else if (value.equalsIgnoreCase("loginUser")) {
Cookie sessionCookie = getCookie(httpServletRequest, "WITSessionCookie");
if (sessionCookie == null) { //user 30 min timeout
session.setAttribute("logedin", "0");
Cookie changeUserCookie = new Cookie("userCookie", "normal");
changeUserCookie.setPath("/");
httpServletResponse.addCookie(changeUserCookie);
//If user generate ajax request
if ("partial/ajax".equals(httpServletRequest.getHeader("Faces-Request"))) {
httpServletResponse.setContentType("text/xml");
httpServletResponse.getWriter().append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").printf("<partial-response><redirect url=\"%s\"></redirect></partial-response>", timeoutPage);
} else {
httpServletResponse.sendRedirect(timeoutPage);
}
filterChain.doFilter(httpServletRequest, httpServletResponse);
} else { //User was login but its session timeout not expire
session.setAttribute("logedin", "0");
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
}
} //end of if (userCookie != null)
首先我在我的web.xml文件中使用这些行
<session-config>
<session-timeout>
10
</session-timeout>
</session-config>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/faces/SessionExpire.xhtml</location>
</error-page>
如果我按原样保留选项,那么当会话超时时,我会看到会话过期的消息。我不想要,因为公共用户与会话无关。
if (value.equalsIgnoreCase("normal")) {
session.setAttribute("logedin", "0");
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
但如果我注释掉该选项,那么我会得到ViewExpiredException。像
<!--
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/faces/SessionExpire.xhtml</location>
</error-page>
-->
WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
javax.faces.application.ViewExpiredException: viewId:/index.xhtml - View /index.xhtml could not be restored.
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:212)
所以我想问是否有任何方法,在普通用户的情况下,该选项不起作用并且只是传递请求,并且在登录用户选项工作的情况下意味着将用户重定向到会话过期消息。 感谢