6

RichFacecs で JSF を使用して Web ポータルを作成しています。セッション タイムアウト時にユーザーをログイン ページにリダイレクトしたいと考えています。次のように、セッションの有効期限/ログアウト段階で SecurityException をスローしようとしていました

<error-page>
    <exception-type>java.lang.SecurityException</exception-type>
    <location>/Login.jsf</location>
</error-page>

しかし、これは私にとってはうまくいきません。これを処理する正しい方法はどれですか?

4

5 に答える 5

7

これはそれを行う必要があります:

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/sessionExpired.jsf</location>
</error-page>
于 2009-09-17T20:24:09.737 に答える
4

このスレッドに示されているように、 web.xmlにタイムアウトを設定し、タイムアウト フィルタを登録する必要があり ます。

    String facesRequestHeader = httpServletRequest
            .getHeader( "Faces-Request" );

    boolean isAjaxRequest = facesRequestHeader != null
            && facesRequestHeader.equals( "partial/ajax" );

    if( isAjaxRequest )
    {
            String url = MessageFormat.format( "{0}://{1}:{2,number,####0}{3}",
            request.getScheme(), request.getServerName(),
            request.getServerPort(), timeoutPath );

            PrintWriter pw = response.getWriter();
                pw.println( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" );
            pw.println( "<partial-response><redirect url=\"" + url
            + "\"></redirect></partial-response>" );
            pw.flush(););
    }
    else
    {
        httpServletResponse.sendRedirect( timeoutPath );
    }
于 2012-05-03T12:04:59.437 に答える
1

セッションの有効期限が切れた後に A4J リクエストを行うと、いくつかの問題が発生しました。私はこれを置きます

<context-param>
    <param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
    <param-value>true</param-value>
</context-param>

私のweb.xmlでは、私にとっては問題を解決します。

于 2011-05-02T14:58:35.233 に答える
0

別の解決策は、ViewHandlerを拡張してrestoreViewメソッドをオーバーライドするCustomViewHandlerを作成することです。

@Override
public UIViewRoot restoreView(FacesContext facesContext, String viewId) {
/**
 * {@link javax.faces.application.ViewExpiredException}. This happens only  when we try to logout from timed out pages.
 */
    UIViewRoot root = null; 
    root = parent.restoreView(facesContext, viewId);
    if(root == null) {          
        root = createView(facesContext, viewId);
    }
    return root;
}

次に、それをfaces-config.xmlに追加する必要があります

<view-handler>com.demo.CustomViewHandler</view-handler>

これにより、ViewExpiredExceptionが発生しなくなります

于 2009-10-19T15:57:23.603 に答える