问题
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.
回答1:
"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...
回答2:
refer above:
first the container will try index.html and if it does not exist, then it will try index.jsp.
my app alway use index.html, when there are both index.jsp, index.html, regardless of the config sequense.
来源:https://stackoverflow.com/questions/5489736/web-xml-default-file-in-directory-for-jetty-or-tomcat