1

ErrorPage.jspがあります。

<h:messages styleClass="messageError" id="messages1"></h:messages>

バッキングBeanコンストラクターで例外が発生した場合、それをキャッチして次のようにします

public constructorxxx throws Exception{
    // code 
// code 
// code
catch(Exception e){
try{
        LOG.error(e);
        String customMessage = "An Unknown Error At " + e.getStackTrace()[0].toString() +  "at" + message;

        getFacesContext().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, 
                customMessage, null));
throw new Exception();
                }catch (IOException exception){   
            LOG.error(exception);   
    } 
}
} // end of constructor

私のWeb.xmlでは、次のタグを使用しました。

<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/ErrorPage.jsp</location>    

そうすると、次のエラーが発生します

1) Uncaught service() exception root cause Faces Servlet: javax.servlet.ServletException
2) An exception was thrown by one of the service methods of the servlet [/sc00/ErrorPage.jsp] in application [MembershipEligibilityScreensEAR]. Exception created : [java.lang.RuntimeException: FacesContext not found.

and in my page it displays as
SRVE0260E: The server cannot use the error page specified for your application to handle the Original Exception printed below.

Error Message: javax.servlet.ServletException
Error Code: 500
Target Servlet: Faces Servlet
Error Stack: 
java.lang.Exception 
// stack trace


Error Message: java.lang.RuntimeException: FacesContext not found
Error Code: 0
Target Servlet: 
Error Stack: 
java.lang.RuntimeException: FacesContext not found 

多くの人から、ErrorPage.jspの場所を/sc00/ErrorPage.facesに変更するように求められましたが、web.xmlにリンク切れの警告が表示され、Webページを表示できないというエラーとプログラミングエラーが発生します。

jsf 1.2を使用していますが、「ErrorPage.jsp」にバッキングBeanがありません。

Error.jspが表示されない理由を誰かに教えてもらえますか?

4

1 に答える 1

3

Facesメッセージはリクエストスコープであるため、現在のHTTPリクエスト/レスポンスサイクルと同じ有効期間があります。ただし、リダイレクトを送信して新しいHTTPリクエストを作成するようにWebブラウザに指示しています。フェイスメッセージは、新しいHTTPリクエストにはもうありません。

<error-page>例外をスローし、のエントリによって特定のエラーページを特定の例外に関連付ける方がよいでしょうweb.xml。servletcontainerは、同じリクエスト内の特定のエラーページに自動的に転送します。

例えば

getFacesContext().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, customMessage, null));
throw new SomeException();

<error-page>
    <exception-type>com.example.SomeException</exception-type>
    <location>/sc00/ErrorPage.faces</location>
</error-page>

ただし、特定のコンテナとJSF impl / versionがJSFベースのエラーページに転送できない場合(無限ループで実行されているか)、最善の策は、エラーページからすべてのJSFコンポーネントを削除することです(そうでない場合は、 )を取得RuntimeException: FacesContext not foundし、HTMLとJSTLのみを含む非常に単純なバニラJSPページにします。

<error-page>
    <exception-type>com.example.SomeException</exception-type>
    <location>/sc00/ErrorPage.jsp</location>
</error-page>

面メッセージとして追加するのではなく、例外自体にのみメッセージを配置する必要があります。

throw new SomeException(customMessage);

次に、次のようにエラーページに表示できます。

${requestScope['javax.servlet.error.message']}

例外を手放すこともできます(つまりthrows、アクションメソッドのように再宣言するだけです。

public void doSomething() throws SomeException {
    // ...
}

とにかく、servletcontainerは自動的にログに記録します。

于 2013-01-08T00:20:13.560 に答える