1

有没有一种方法可以告诉我的应用程序让每个页面(比如说 .jsp 页面)都进入 faces 上下文?

在我的web.xml我很容易做一个servlet映射,类似于:

<servlet-mapping>
   <servlet-name>Faces Servlet</servlet-name>
   <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
   <servlet-name>Faces Servlet</servlet-name>
   <url-pattern>*.jsf</url-pattern>
</servlet-mapping>

我可以在其中映射每个 url,包括/faces/虚拟路径或以 .jsf 结尾,以由代表 jsf 引擎的 servlet 处理。

但是,如果我希望我的应用程序中的所有内容都在 faces 上下文中呢?我尝试添加:

<servlet-mapping>
   <servlet-name>Faces Servlet</servlet-name>
   <url-pattern>*.jsp</url-pattern>
</servlet-mapping>

但似乎应用程序立即崩溃:

NAQ Exception in PhaseListener RESTORE_VIEW(1) afterPhase
java.lang.NullPointerException
 at net.sf.jsfcomp.clientvalidators.ValidatorResourceLoader.afterPhase(Unknown Source)
 at org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersAfter(PhaseListenerManager.java:92)
 at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:99)
 at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:691)
 at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:469)
 at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:403)
 at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
 at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:419)
 at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
 at it.asg.utility.viewhandlers.UrlParameterViewHandler.renderView(UrlParameterViewHandler.java:116)
 at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
 at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:691)
 at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:469)
 at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:403)
 at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
 at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:419)
 at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
 at it.asg.utility.viewhandlers.UrlParameterViewHandler.renderView(UrlParameterViewHandler.java:116)
 at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
 at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)

怎么了?有没有办法让面孔上下文适用于我的应用程序中的每个页面?

4

1 回答 1

4

这是不可能的,因为*.jsp要由 servletcontainer 的 builtin 解析JspServlet

理论上你可以使用url-patternof /*

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

然而,这在实践中不起作用(被FacesServlet.

尽量不要思考/寻找艰难/繁琐的方式。只需使用*.jsf并在必要时添加一个安全约束*.jsp来阻止对 JSP 的直接访问,正如我在上一个问题中所建议的那样。这是常见的做法。

或者,您也可以从 JSP 升级到基于 XHTML/XML 的Facelets 。这样,您可以使用*.xhtml甚至*.html作为 Facelets 后缀和FacesServlet映射。

于 2010-08-02T17:00:37.063 回答