Example Application Deployment Descriptor

Example F-3 shows an example of a deployment descriptor (web.xml) file with the most common declarations needed for a JSF- application.

Example F-3. Example deployment descriptor file
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
  version="2.4>

  <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>

  <servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>
      javax.faces.webapp.FacesServlet
    </servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
  </servlet-mapping>
</web-app>

At the top of the file, you find a standard XML declaration and the <web-app> element, with the reference to the deployment descriptor schema. Next comes a <context-param> element that tells JSF to save state in the client. The <servlet> element maps the JSF servlet class to a name, and the <servlet-mapping> element maps the servlet to the recommended *.faces extension pattern.

Get JavaServer Faces now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.