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 deploy the example using NetBeans IDE, right-click on the project in the Projects pane and<br />

select Undeploy and Deploy.<br />

To deploy the example using Ant, type ant deploy. <strong>The</strong> deploy target in this case gives you an<br />

incorrect URL to run the application. To run the application, please use the URL shown at the<br />

end of this section.<br />

To run the application, first deploy the web module, and then open the URL<br />

http://localhost:8080/hello2/greeting in a browser.<br />

DeclaringWelcome Files<br />

ConfiguringWeb Applications<br />

<strong>The</strong> welcome files mechanism allows you to specify a list of files that the web container will use<br />

for appending to a request for a URL (called a valid partial request) that is not mapped to a web<br />

component.<br />

For example, suppose you define a welcome file welcome.html. When a client requests a URL<br />

such as host:port/webapp/directory, where directory is not mapped to a servlet or JSP page, the<br />

file host:port/webapp/directory/welcome.html is returned to the client.<br />

If a web container receives a valid partial request, the web container examines the welcome file<br />

list and appends to the partial request each welcome file in the order specified and checks<br />

whether a static resource or servlet in the WAR is mapped to that request URL. <strong>The</strong> web<br />

container then sends the request to the first resource in the WAR that matches.<br />

If no welcome file is specified, the Application Server will use a file named index.XXX, where<br />

XXX can be html or jsp, as the default welcome file. If there is no welcome file and no file<br />

named index.XXX, the Application Server returns a directory listing.<br />

To specify a welcome file in the web application deployment descriptor using NetBeans IDE, do<br />

the following:<br />

1. Open the project if you haven’t already.<br />

2. Expand the project’s node in the Projects pane.<br />

3. Expand the Web Pages node and then the WEB-INF node.<br />

4. Double-click web.xml.<br />

5. Do one of the following, making sure that the JSP pages you specify are actually included in<br />

the WAR file:<br />

a. Click Pages at the top of the editor pane and enter the names of the JSP pages that act as<br />

welcome files in the Welcome Files field.<br />

b. Click XML at the top of the editor pane, specify the JSP pages using welcome-file<br />

elements and include these elements inside a welcome-file-list element. <strong>The</strong><br />

welcome-file element defines the JSP page to be used as the welcome page.<br />

Chapter 3 • Getting Started withWeb Applications 91

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

Saved successfully!

Ooh no, something went wrong!