web.xml default file in directory (for jetty, or tomcat)?

19,214

"hey, whenever you get a request for a directory, see if there is an ./index.jsp -- and display it to the user."

That's exactly what welcome-file-list is supposed to do.

Simply add the following to web.xml. In this case, first the container will try index.html and if it does not exist, then it will try index.jsp.

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

I've tested this on Tomcat 5.5, and it works correctly.

Unfortunately, it's really hard to find the official reference for web.xml. So here is the documentation for Oracle weblogic instead; I think it can be trusted...

Share:
19,214

Related videos on Youtube

somid3
Author by

somid3

Updated on May 26, 2022

Comments

  • somid3
    somid3 almost 2 years

    I have a directory called ./welcome/ and ./welcome/ has a file called ./index.jsp.

    I know how to tell jetty or tomcat how to start at ./wecome/index.jsp. But, I also have lots of other directories with an ./index.jsp like --- ./blogs/, ./whatever/, etc.

    Without using servlets, is there a way to tell jetty or tomcat, "hey, whenever you get a request for a directory, see if there is an ./index.jsp -- and display it to the user."

    Like if I access ./blogs/ I dont want to see a 404 not found. I want to see the contents of ./blogs/index.jsp, but I dont want my users to be redirected to ./blogs/index.jsp -- I want their browsers to still only display ./blogs/

    I know apache has such as feature. Any help would be appreciated, thanks.

  • somid3
    somid3 about 13 years
    oh! haha, this was such a silly question come to think about it. I thought I had it all correct, by my welcome-file-list was set to ./welcome/index.jsp -- no wonder, thanks!