0

2人のユーザーがいます。公開してログインします。ユーザーがパブリックでセッションがタイムアウトした場合、私は単に次のようなリクエストを渡します

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)

だから私は、通常のユーザーの場合はオプションが機能せず、単にリクエストを渡す方法がありますか?ログインユーザーオプションの場合は、ユーザーをセッションの期限切れメッセージにリダイレクトすることを意味します。ありがとう

4

0 に答える 0