Welcome Files

Web application developers can specify an ordered list of welcome files to be loaded when the request URL is not mapped to a servlet. These files are typically HTML or JSP documents. Welcome files are defined using the welcome-file-list element in the deployment descriptor. Element welcome-file-list contains one or more welcome-file elements. Each welcome-file element specifies the partial URL of a welcome file without a leading or trailing /. For example, the following welcome-file-list element indicates that index.html and index.htm are the welcome files.

index.html index.htm

To specify the welcome files for the jhtp6 context root, insert the preceding welcomefile-list element after the last servlet-mapping element in the web.xml deployment descriptor. When the URL http://localhost:8080/jhtp6/ is requested, the Web server appends each welcome file in the order specified in the deployment descriptor to the request URL, such as

http://localhost:8080/jhtp6/index.html http://localhost:8080/jhtp6/index.htm

and checks whether the resource is valid. The servlet container sends the request to the first matching welcome file. For example, if index.html exists in the jhtp6 directory, the servlet container sends the request to the http://localhost:8080/jhtp6/index.html. If no matching welcome file is found, the servlet container returns a response indicating that the resource is not available.

Figure 26.24 is the index.html that provides links (lines 1524) to test all the examples demonstrated in this chapter. Copy this file to C:jakarta-tomcat-5.0.25webappsjhtp6 and restart the Tomcat server. To test the welcome file, type the following URL in your Web browser:

Figure 26.24. Welcome file index.html.

(This item is displayed on page 1273 in the print version)

"http://www.w3.org/1999/xhtml"> 8 9

1 6 7

Welcome File 10 11 12 13

Click a link to test each example demonstrated in this chapter

14

15 <a href="</span"> "/jhtp6/servlets/WelcomeServlet.html"> 16 WelcomeServlet</a>

17 <a href="</span"> "/jhtp6/servlets/WelcomeServlet2.html"> 18 WelcomeServlet2</a>

19 <a href="</span"> "/jhtp6/servlets/WelcomeServlet3.html"> 20 WelcomeServlet3</a>

21 <a href="</span"> "/jhtp6/servlets/RedirectServlet.html"> 22 RedirectServlet</a>

23 <a href="</span"> "/jhtp6/servlets/Survey.html"> 24 SurveyServlet</a>

25

26 27

http://localhost:8080/jhtp6/

 

The index.html page is loaded. Click a link to test the corresponding servlet example.

Категории