简体   繁体   English

JSF项目可以在不使用Servlet的情况下运行吗?

[英]Can a JSF Project run without using Servlets?

I am new to JSF and I have a question: 我是JSF的新手,我有一个问题:

As far as I know Servlets are classes that are used to get HTML requests and to provide HTML responses. 据我所知,Servlet是用于获取HTML请求和提供HTML响应的类。 Such as: 如:

HttpServletRequest request, HttpServletResponse response HttpServletRequest请求,HttpServletResponse响应

But in a typical JSF project, I do not see these classes used at all, instead all I see is managed beans and Facelet pages. 但是在一个典型的JSF项目中,我根本看不到这些类,而是我看到的只是托管bean和Facelet页面。

However in web.xml I see: 但是在web.xml中我看到:

<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>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

Also JSTL.jar's are required to build a JSF Project as far as I understand. 据我所知,JSTL.jar也需要构建一个JSF项目。

So are these classes 这些课程也是如此

HttpServletRequest request, HttpServletResponse response HttpServletRequest请求,HttpServletResponse响应

still used in a JSF Project? 仍然在JSF项目中使用? If so how? 如果是这样的话?

javax.servlet.http.HttpServlet is used. javax.servlet.http.HttpServlet It is extended by the FacesServlet (meaning it is an javax.servlet.http.HttpServlet ). 它由FacesServlet扩展(意味着它是一个javax.servlet.http.HttpServlet )。 JSF FacesServlet loads the view, builds a component tree, processes events, and renders the response. JSF FacesServlet加载视图,构建组件树,处理事件和呈现响应。

As others have indicated, JSF itself is implemented with important ties to Servlet technology. 正如其他人所指出的那样,JSF本身与Servlet技术有着重要的联系。 The Faces Servlet is itself, well, a Servlet. Faces Servlet本身就是一个Servlet。

Do note that the mapping in web.xml that you showed is optional for a JSF 2.1 implementation running on a Java EE 6 (specifically Servlet 3) container. 请注意,您显示的web.xml中的映射对于在Java EE 6(特别是Servlet 3)容器上运行的JSF 2.1实现是可选的。 In that case the extensions .jsf and .faces as well as the path faces\\* are automatically mapped to the Faces Servlet, and thus to your pages. 在这种情况下,扩展名.jsf.faces以及路径faces\\*会自动映射到Faces Servlet,从而映射到您的页面。

JSF itself does try to abstract from Servlet technology. JSF本身确实试图从Servlet技术中抽象出来。 For instance, there's the type ExternalContext that abstracts from the "nature of its containing application environment". 例如, ExternalContext类型从“包含应用程序环境的本质”中抽象出来。 In practice this means it's compatible with both Servlets and Portlets. 实际上,这意味着它与Servlet和Portlet兼容。 But, at least one of those 2 environments is needed with the current versions. 但是,当前版本至少需要这两种环境中的一种。

Theoretically someone could port a JSF implementation to a non-Servlet and non-Portlet environment, but to the best of my knowledge nobody has done this yet. 从理论上讲,有人可以将JSF实现移植到非Servlet和非Portlet环境中,但据我所知,没有人能够做到这一点。

They are used, since JSF itself is provided by a Servlet named javax.faces.webapp.FacesServlet . 它们被使用,因为JSF本身是由名为javax.faces.webapp.FacesServlet的Servlet提供的。 That is when someone calls your view they end up calling servlet defined in javax.faces.webapp.FacesServlet , this servlet then will do all magic JSF stuff that renders your XML page. 也就是说当有人调用你的视图时,他们最终会调用javax.faces.webapp.FacesServlet定义的servlet,然后这个servlet将执行渲染XML页面的所有魔法JSF。

Depending on the JSF implementation it might be possible to run without using Servlets. 根据JSF实现,可以在不使用Servlet的情况下运行。 While the JSF standard requires implementers to provide a Servlet based implementation for portability it allows implementers to support other ways to invoke the JSF lifecycle. 虽然JSF标准要求实现者提供基于Servlet的实现以实现可移植性,但它允许实现者支持其他方式来调用JSF生命周期。 (Stated in Section 11.1.1 of the standard ) (见标准第11.1.1节)

However I'm not aware that there actually is any implementation that does provide this possibility. 但是我不知道实际上有任何实现确实提供了这种可能性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM