*.jsp 的 jsf sevlet 映射

发布于 2024-09-12 16:08:58 字数 3617 浏览 6 评论 0原文

有没有办法告诉我的应用程序让每个页面(比如说 .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)

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

Is there a way I can tell my application to let every single page (let's say .jsp pages) to go under faces context?

In my web.xml I easly can do a servlet-mapping similar to:

<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>

Where I can map every url including /faces/ virtual path or ending in .jsf to be processed by the servlet rapresenting the jsf engine.

But what if I want that everything in my application goes under the faces context?
I tried adding:

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

But it seems that the application crashes immediately:

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)

What's wrong? Is there a way to let faces context work for every page in my app?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡写薰衣草的香 2024-09-19 16:08:58

这是不可能的,因为 *.jsp 将由 servletcontainer 的内置 JspServlet 进行解析。

理论上,您可以使用 /*url-pattern

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

然而,这在实践中是行不通的(FacesServlet 不允许),并且只会为不需要经历整个 JSF 生命周期的请求增加不必要的开销。

尽量不要去思考/寻找困难/麻烦的方法。只需使用 *.jsf ,并在必要时在 *.jsp 上添加安全约束,以阻止对 JSP 的直接访问,正如我在 上一个问题。这是常见的做法。

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

That's not possible because *.jsp is to be parsed by the servletcontainer's builtin JspServlet.

You could in theory use an url-pattern of /*.

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

This will in practice however not work (disallowed by the FacesServlet) and it would only add unnecessary overhead to requests which doesn't need to go through the whole JSF lifecycle.

Try to not think/look for the hard/cumbersome way. Just use *.jsf and if necessary add a security constraint on *.jsp to block direct access to JSP as I suggested in your previous question. That's the common practice.

Alternatively, you can also upgrade from JSP to Facelets which is XHTML/XML based. This way you can use *.xhtml or even *.html as both the Facelets suffix and the FacesServlet mapping.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文