Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a JSF Project run without using Servlets?

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?

like image 971
Koray Tugay Avatar asked Apr 20 '26 00:04

Koray Tugay


1 Answers

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.

like image 195
Arjan Tijms Avatar answered Apr 23 '26 15:04

Arjan Tijms