Configuring welcome files in the DD

You already know that if you type in the name of a web site and you don’t specify a specific file, you (usually) still get something back. Entering http://www.oreilly.com into your browser takes you to the O’Reilly web site, and even though you didn’t name a specific resource (like “home.html”, for example), you still get a default page.

You can configure your server to define a default page for the entire site, but we’re concerned here with default (also known as “welcome”) pages for individual web apps. You configure welcome pages in the DD, and that DD determines what the Container chooses when the client enters a partial URL—a URL that includes a directory, for example, but not a specific resource in the directory.

In other words, what happens if the client request comes in for:

http://www.wickedlysmart.com/foo/bar

Note

“bar” is just a directory

and “bar” is simply a directory, and you don’t have a specific servlet mapped to this URL pattern. What will the client see?

In the DD:

image with no caption

Imagine you have a web app where several different directories have their own default HTML page, named “index.html”. But some directories use a “default.jsp” instead. It would be a huge pain if you had to specify a specific default page or JSP for each directory that needs one. Instead, you specify a list, in order, of the pages you want the Container to look for in whatever directory the partial request is for. In other words, no matter which directory is requested, the Container always looks through the same list—the one and only <welcome-file-list>.

The Container will pick the first match it finds, starting with the first welcome file listed in the <welcome-file-list>.

Note

Multiple welcome files go in a single DD element.

No matter how many welcome files you might list, you put them ALL into a single entry in the DD: <welcome-file-list>. It’s tempting to think that each file might go in a separate <welcome-file-list> element, but that’s not how it works! Each file has its own <welcome-file> element, but you put ALL of them within a single <welcome-file-list>.

Note

The files in the <welcome-file> element do NOT start with a slash!

Don’t be confused. The way in which the Container matches and chooses welcome files is not the same as the way in which it matches URL patterns. If you put the slash in front of the file name, you’ll be violating the spec, and bad things will happen.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset