background image

Declaring WelcomeFiles

<< Perform the Servlet Mappings | Setting Initialization Parameters >>
<< Perform the Servlet Mappings | Setting Initialization Parameters >>

Declaring WelcomeFiles

To package the example with the Ant utility, do the following:
1. In a terminal window, go to tut-install/javaeetutorial5/examples/web/hello2/.
2. Type ant. This target will build the WAR file and copy it to the
tut-install/javaeetutorial5/examples/web/hello2/dist/ directory.
To deploy the example using NetBeans IDE, right-click on the project in the Projects pane and
select Deploy Project.
To deploy the example using Ant, type ant deploy. The deploy target in this case gives you an
incorrect URL to run the application. To run the application, please use the URL shown at the
end of this section.
To run the application, first deploy the web module, and then open the URL
http://localhost:8080/hello2/greeting
in a browser.
Declaring Welcome Files
The welcome files mechanism allows you to specify a list of files that the web container will use
for appending to a request for a URL (called a valid partial request) that is not mapped to a web
component.
For example, suppose you define a welcome file welcome.html. When a client requests a URL
such as host:port/webapp/directory, where directory is not mapped to a servlet or JSP page, the
file host:port/webapp/directory/welcome.html is returned to the client.
If a web container receives a valid partial request, the web container examines the welcome file
list and appends to the partial request each welcome file in the order specified and checks
whether a static resource or servlet in the WAR is mapped to that request URL. The web
container then sends the request to the first resource in the WAR that matches.
If no welcome file is specified, the Application Server will use a file named index.XXX, where
XXX can be html or jsp, as the default welcome file. If there is no welcome file and no file
named index.XXX, the Application Server returns a directory listing.
To specify a welcome file in the web application deployment descriptor using NetBeans IDE, do
the following:
1. Open the project if you haven't already.
2. Expand the project's node in the Projects pane.
3. Expand the Web Pages node and then the WEB-INF node.
4. Double-click web.xml.
5. Do one of the following, making sure that the JSP pages you specify are actually included in
the WAR file:
Configuring Web Applications
Chapter 3 · Getting Started with Web Applications
91