0

I'm using Apache Tomcat 7.0 Servlet Container. I've been trying to look at the request handling in JavaServer Faces. I can see the following chunk of config in the 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>*.html</url-pattern>
  </servlet-mapping>

I've looked at the source of the Faces Servlet, but I haven't found doGet method inside. I thought doGet method is one of the principal method to handle HTTP GET request in the Java Servlets. So who exact handles incoming GET request in JSF? I would like to look at the method, which do that.

1 Answers1

3

FacesServlet doesn't extend from HttpServlet class containing a.o. doGet(). It just implements Servlet interface which offers the base service() method. Look here.

JSF is designed to be compatible with both servlets and portlets. Portlets doesn't use HttpServlet, but PortletServlet which shares the common Servlet interface.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • That is, service method will be called when http request is come to a server, won't it? –  Aug 18 '14 at 12:15
  • Yup. Have you looked in source code of [`HttpServlet`](http://grepcode.com/file/repo1.maven.org/maven2/javax.servlet/javax.servlet-api/3.0.1/javax/servlet/http/HttpServlet.java#HttpServlet.service%28javax.servlet.http.HttpServletRequest%2Cjavax.servlet.http.HttpServletResponse%29)? Check when exactly `doGet()` will be called. See also http://stackoverflow.com/questions/5370633/405-http-method-get-is-not-supported-by-this-url/ for related answer on that part. – BalusC Aug 18 '14 at 12:16
  • Yes, I do. It seems core of the method is starting JSF lifecycle and further rendering page with `lifecycle.execute(context); lifecycle.render(context);` –  Aug 18 '14 at 12:19
  • Yup. Don't forget to click the `service()` link in my answer for the definitive answer. – BalusC Aug 18 '14 at 12:21
  • I've found `lifecycle = lifecycleFactory.getLifecycle(lifecycleId);` inside the `init()` method body. Is `lifecycle` object destroyed after the request handling is completed? –  Aug 18 '14 at 12:26
  • This is a different question. Just look at the source code and read Servlet API specs/javadocs or press `[Ask Question]` button. In the meanwhile, this may be helpful to get better insight into basic servlet API: http://stackoverflow.com/questions/3106452/how-do-servlets-work-instantiation-session-variables-and-multithreading/ – BalusC Aug 18 '14 at 12:28