【问题标题】:Why jsf can't handle jsf error pages?为什么jsf不能处理jsf错误页面?
【发布时间】:2011-12-11 14:07:38
【问题描述】:

我在web.xml 中提到了一个错误页面error.jsf

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/viewExpired.jsp</location>
</error-page>
<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/error.jsp</location>
</error-page>

如果文件是 .jsf,则不会触发错误页面,当我将其更改为 .jsp 时,一切正常。 我也实现了一个过滤器,但仍然没有。

<filter>
    <filter-name>Error</filter-name>
    <filter-class>creazione.exception.MyFilter</filter-class>
</filter>

这是 JSF 无法处理的事情吗?

更新 web.xml 中带有 url 模式映射的代码:

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>

【问题讨论】:

    标签: java jsp jsf jsf-2


    【解决方案1】:

    如果您实际使用 Facelets 作为默认视图技术(在 JSF 2.0 中标准化),就会发生这种情况。您的问题历史记录还确认您使用的是 Facelets,而不是其遗留的前身 JSP。您还需要将这些错误页面制作成 Facelets 文件,而不是 JSP 文件。

    过滤器不“工作”是由其他原因引起的。过滤器与 JSF 结合运行完全没有问题。

    【讨论】:

    • 为什么我需要制作错误页面 Facelets 文件?如果它们是 .jsf 还不是 facelets?我不明白...
    • JSP 是一种古老的视图技术。 Facelets (XHTML) 是 JSP 的继承者。 JSF 2.0 默认使用 Facelets。 “.jsf”文件实际上并不存在于磁盘上。它们是指向具体 JSP (.jsp) 或 Facelet (.xhtml) 文件的虚拟 URL 映射。 JSF 2.0 默认使用 Facelets。
    • 虽然我的 error.xhtml 页面是提供给我的,但它通过 FacesServlet 提供。我不知道我是否在这里遗漏了什么,但我正在编写一个 servlet 用作 web.xml 中的 ,它将重定向到我的 error.xhtml 页面。
    • @Markos:URL 模式应该匹配 FacesServlet &lt;url-pattern&gt;。如果你有&lt;location&gt;/error.xhtml&lt;/location&gt;,那么它应该映射到*.xhtml 以使其工作。
    • 是的,Faces Servlet 映射到 *.xhtml 并且错误页面是 error.xhtml。我正在为 faces servlet 之外的页面提供服务!如果我直接点击它的 URL,它就是由 faces servlet 提供的,正如预期的那样。我的印象是,当在 faces servlet 内引发异常时,它会被容器捕获和处理,然后转发到我的 error.xhtml 页面,而不是通过 faces servlet 提供它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    • 1970-01-01
    • 2011-09-01
    • 2012-08-03
    • 2012-12-15
    相关资源
    最近更新 更多