Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 513
somid3 Avatar asked Mar 30 '11 17:03

somid3


1 Answers

"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...

like image 65
Leonel Avatar answered Nov 09 '22 05:11

Leonel