0

我在 web.xml 中配置错误页面如下:

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

在我的index.xhtml 中有一个输入字段:

 <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