0

次のように web.xml でエラーページを構成します。

 <error-page>
        <exception-type>java.lang.Throwable</exception-type>
        <location>/faces/error.xhtml</location>        
    </error-page>

私のindex.xhtmlには、入力フィールドが 1 つあります。

 <h:form>
        <h:inputText value="#{errorBean.text}"  />
        <h:commandButton value="submit" action="index.xhtml"/>
    </h:form>

そして、私のManagedBeanはユーザー入力をチェックしました。ユーザーが何も入力しない場合、Bean は次のように例外をスローします。

@ManagedBean(name = "errorBean")
@SessionScoped
public class ErrorBean {

    private String text;
    private Exception e;

    /**
     * Creates a new instance of ErrorBean
     */
    public ErrorBean() {
    }

    public String getText() {
        return text;
    }

    public void setText(String text) throws Exception{
        if (text.equalsIgnoreCase("")) {

         throw new Exception();
        } else {
            this.text = text;
        }
    }   
}

私の質問は、なぜ例外がスローされるのか、ブラウザーの URL は次のとおりです。

 http://localhost:8888/ErrorNavigator/faces/index.xhtml,

それはそうですね:

http://localhost:8888/ErrorNavigator/faces/error.xhtml

ブラウザでURLを設定する方法は次のとおりです。

http://localhost:8888/ErrorNavigator/faces/error.xhtml

私を助けてください!!!!

4

0 に答える 0