background image

Mapping the FacesServlet Instance

<< Steps in the Development Process | Creating the Pages >>
<< Steps in the Development Process | Creating the Pages >>

Mapping the FacesServlet Instance

3. Select the guessNumber folder.
4. Select the Open as Main Project check box.
5. Click Open Project Folder.
6. In the Projects tab, right-click the guessNumber project, and select Deploy Project.
7. To run the application, open the URL http://localhost:8080/guessNumber in a browser.
To build, package, and deploy this example using Ant, follow these steps:
1. Go to tut-install/javaeetutorial5/examples/web/guessNumber/.
2. Type ant.
3. Start the Application Server.
4. Type ant deploy.
5. To run the application, open the URL http://localhost:8080/guessNumber in a browser.
To learn how to configure the example, refer to the deployment descriptor (the web.xml file),
which includes the following configurations:
A display-name element that specifies the name that tools use to identify the application.
A servlet element that identifies the FacesServlet instance.
A servlet-mapping element that maps FacesServlet to a URL pattern.
Mapping the FacesServlet Instance
All JavaServer Faces applications must include a mapping to the FacesServlet instance in their
deployment descriptors. The FacesServlet instance accepts incoming requests, passes them to
the life cycle for processing, and initializes resources. The following piece of the guessNumber
example's deployment descriptor performs the mapping to the FacesServlet instance:
<servlet>
<display-name>FacesServlet</display-name>
<servlet-name>FacesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>/guess/*</url-pattern>
</servlet-mapping>
The mapping to FacesServlet shown above uses a prefix mapping to identify a JSP page as
having JavaServer Faces components. Because of this, the URL to the first JSP page of the
A Simple JavaServer Faces Application
Chapter 10 · JavaServer Faces Technology
289