0

Websphere Process Server(WAS 7の上)にViewExpiredExceptionのあるJSFページがあります。これが発生した場合、ユーザーをログアウトしてから再度ログインさせたいので、web.xmlでこの例外のリダイレクトを次のログアウトページに設定しました。

<%  
  session.invalidate();
  response.sendRedirect("ibm_security_logout?logoutExitPage=/faces/ToDosOpen.jsp");
%>

次に、ログインページにリダイレクトします。

<%@ page import="com.ibm.wbit.tel.client.jsf.infrastructure.Messages, java.util.Locale" language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%
    String contextPath = request.getContextPath();
    Locale locale = request.getLocale();
    final String SECURITY_CHECK = "j_security_check";
%>

...
</head>

<body>
...

<h1><%= Messages.getString("LOGIN_LINE", locale) %></h1>

<div class="help-text"><%= Messages.getString("LOGIN_LINE_DESCR", locale) %></div>

<form target="_top" method="POST" action=<%= SECURITY_CHECK %>>
    <table id="login-form">
        <tr>
            <td><%= Messages.getString("LOGIN_NAME", locale) %>:</td>
            <td><input type="text" name="j_username"></td>
        </tr>
        <tr>
            <td><%= Messages.getString("LOGIN_PASSWORD", locale) %>:</td>
            <td><input type="password" name="j_password"></td>
        </tr>
        <tr> 
            <td id="login-button" colspan="2">
<input type="submit" name="login" value="
<%= Messages.getString("BUTTON_LOGIN", locale) %>"></td>
            </tr>
    </table>

 </form>

そして、ログインすると、そもそも例外の原因となったページにリダイレクトされます。実際に発生することを除いて、例外が再度スローされ、ログインページに戻ります。

したがって、2回ログインする必要があります。

これについて何をすべきか、どこから探し始めるかわからない。どんな助けでもいただければ幸いです。私はこれに関する既存の質問を調べましたが、それを解決することができませんでした。


編集:例外をトリガーしたアクションが更新の場合は正常に機能しますが、アクションがコマンドバーをクリックした場合は失敗します(2回ログインする必要があります)。

4

1 に答える 1

0

最後に、次の ViewHandler を使用して解決しました。これは基本的に、有効期限が切れたビューを再作成します。POST パラメーターがあった場合、それらは明らかに失われているため、それらがないと作成できないビューには特別な処理が必要です。

これがこの問題に遭遇した他の人に役立つことを願っています.100%の自信があるわけではないので、この解決策に何か問題がある場合はお知らせください.

/**
 * This class just handles cases where the session expired
 * which causes an exception on reload.
 */
public class ViewExpiredHandler extends ViewHandlerWrapper {

private ViewHandler wrapped;

public ViewExpiredHandler(ViewHandler wrapped) {
    this.wrapped = wrapped;
}

@Override
public UIViewRoot restoreView( FacesContext ctx, String viewId )
{
    UIViewRoot viewRoot = super.restoreView( ctx, viewId );
    try {
        if ( viewRoot == null) {

            viewRoot = super.createView( ctx, viewId );
            ctx.setViewRoot( viewRoot );

        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return viewRoot;
}

@Override
protected ViewHandler getWrapped() {
    return wrapped;
}
}
于 2012-05-10T21:02:44.193 に答える