10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

To make sure that the FacesServlet instance is invoked, you provide a mapping to it. <strong>The</strong><br />

mapping to FacesServlet can be a prefix mapping, such as /guess/*, or an extension<br />

mapping, such as *.faces. <strong>The</strong> mapping is used to identify a JSP page as having <strong>Java</strong>Server<br />

Faces content. Because of this, the URL to the first JSP page of the application must include the<br />

mapping.<br />

In the case of prefix mapping, there are two ways to accomplish this:<br />

■ <strong>The</strong> page author can include an HTML page in the application that has the URL to the first<br />

JSP page. This URL must include the path to FacesServlet, as shown by this tag, which uses<br />

the mapping defined in the guessNumber application:<br />

<br />

■ Users of the application can include the path to FacesServlet in the URL to the first page<br />

when they enter it in their browser, as shown by this URL that accesses the guessNumber<br />

application:<br />

http://localhost:8080/guessNumber/guess/greeting.jsp<br />

<strong>The</strong> second method allows users to start the application from the first JSP page, rather than start<br />

it from an HTML page. However, the second method requires users to identify the first JSP<br />

page. When you use the first method, users need only enter<br />

http://localhost:8080/guessNumber<br />

Basic Requirements of a <strong>Java</strong>Server Faces Application<br />

In the case of extension mapping, if a request comes to the server for a JSP page with a .faces<br />

extension, the container will send the request to the FacesServlet instance, which will expect a<br />

corresponding JSP page of the same name to exist containing the content. For example, if the<br />

request URL is http://localhost/bookstore6/bookstore.faces, FacesServlet will map it<br />

to the bookstore.jsp page.<br />

If you are using NetBeans IDE, the time to map the FacesServlet instance is when you create<br />

your <strong>Java</strong>Server Faces project with NetBeans IDE:<br />

1. In NetBeans IDE, select File→New Project.<br />

2. In the New Project dialog, select Web from the Categories tree.<br />

3. Select Web Application from the Projects panel.<br />

4. Click Next.<br />

5. Fill out the information in the Name and Location screen of the wizard.<br />

6. Click Next.<br />

7. Select the <strong>Java</strong>Server Faces check box in the Framewoks screen.<br />

8. Enter the mapping, such as *.faces, to the FacesServlet instance in the Servlet URL<br />

Mapping field.<br />

9. Click Finish.<br />

Chapter 14 • Configuring <strong>Java</strong>Server Faces Applications 457

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!