0

ポータルのログイン ページからインデックス ページに移動すると、いくつかの事実に基づいて、ユーザーが外部にリダイレクトされる可能性がある状況が発生します。これは次のようになります。

if (!(marketVo.getAbsoluteUrl() != null && marketVo.getAbsoluteUrl().equals(absoluteUrlToRedirect))) {
logger.info("---WILL REDIRECT TO ABS URL: " + absoluteUrlToRedirect);
final FacesContext context = FacesContext.getCurrentInstance();
context.responseComplete();
try {
    final HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();

    if (context.getViewRoot() != null) {
        // this step will clear any queued events
        context.getViewRoot().processDecodes(context);
    }
    response.sendRedirect(absoluteUrlToRedirect);

} catch (final Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

}

まあ、それは例外をスローします:

 14:24:35,579 INFO  [CmwSessionHelperBean] ---WILL REDIRECT TO ABS URL: http://hi
tachi.mygravitant.com
14:24:35,580 ERROR [STDERR] java.lang.IllegalStateException
14:24:35,582 ERROR [STDERR]     at org.apache.catalina.connector.ResponseFacade.
sendRedirect(ResponseFacade.java:435)
14:24:35,590 ERROR [STDERR]     at com.example.cloud.common.jsf.core.beans.Cmw
SessionHelperBean.createCmwUserSession(CmwSessionHelperBean.java:269)

この例外が発生しないようにするための提案をお願いできますか? リダイレクトは完了しましたが、この例外により、ポータルに戻ったときに正しく機能していないことに注意してください...

4

1 に答える 1

2

ExternalContext#redirect()JSF セーフな方法でリダイレクトを実行するために使用する必要があります。

public void createCmwUserSession() throws IOException {

    if (!(marketVo.getAbsoluteUrl() != null && marketVo.getAbsoluteUrl().equals(absoluteUrlToRedirect))) {
        logger.info("---WILL REDIRECT TO ABS URL: " + absoluteUrlToRedirect);
        FacesContext.getCurrentInstance().getExternalContext().redirect(absoluteUrlToRedirect);
    }
}

このメソッドは暗黙的に も呼び出しFacesContext#responseComplete()ます。自分で行う必要はありません。

さらに、同じ応答でリダイレクト メソッドを複数回呼び出していないこと、または後でナビゲーションを実行していないことを確認する必要があります。

于 2012-04-06T12:24:20.427 に答える