Reputation: 23844
I am new to JSF and I have a question:
As far as I know Servlets are classes that are used to get HTML requests and to provide HTML responses. Such as:
HttpServletRequest request, HttpServletResponse response
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.
However in web.xml I see:
<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.
So are these classes
HttpServletRequest request, HttpServletResponse response
still used in a JSF Project? If so how?
Upvotes: 3
Views: 1791
Reputation: 2698
javax.servlet.http.HttpServlet
is used. It is extended by the FacesServlet
(meaning it is an javax.servlet.http.HttpServlet
). JSF FacesServlet
loads the view, builds a component tree, processes events, and renders the response.
Upvotes: 3
Reputation: 38163
As others have indicated, JSF itself is implemented with important ties to Servlet technology. The Faces Servlet is itself, well, a 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. 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 itself does try to abstract from Servlet technology. For instance, there's the type ExternalContext that abstracts from the "nature of its containing application environment". In practice this means it's compatible with both Servlets and Portlets. 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.
Upvotes: 3
Reputation: 22043
Depending on the JSF implementation it might be possible to run without using Servlets. 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. (Stated in Section 11.1.1 of the standard)
However I'm not aware that there actually is any implementation that does provide this possibility.
Upvotes: 2
Reputation: 23995
They are used, since JSF itself is provided by a Servlet named javax.faces.webapp.FacesServlet
. 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.
Upvotes: 2