I have read that a jsp file inside WEB-INF cannot be accessed from outside (it must be called from a Servlet).
But, why can the welcome-file in web.xml file, point to a file inside the WEB-INF directory? because this way the file can be accessed from outside :
<welcome-file-list>
<welcome-file>WEB-INF/page.jsp</welcome-file>
</welcome-file-list>
I'm testing with Google App engine and default Servlet container Jetty 6.
It's because the welcome file is served by a RequestDispatcher#forward() call. As evidence, do you see /WEB-INF/page.jsp appearing in browser's address bar? No? Then it's already most definitely not a direct request. If you attempt to request it directly, you'll see that you get a 404.
See also:
- RequestDispatcher.forward() vs HttpServletResponse.sendRedirect()
- Servlets wiki page - contains Hello World examples illustrating real world use cases for
forward()
Unrelated to the concrete problem, you seem to be basically abusing the <welcome-file> to have a "homepage file". There it is not intented for. It's intented to specify the sole filename of the folder's file you'd like to serve up when any folder is been requested, such as /, /foo/, /foo/bar/, etc. If you specify index.jsp, then the /index.jsp, /foo/index.jsp, /foo/bar/index.jsp, etc will transparently be served up by a forward without a change in URL.
来源:https://stackoverflow.com/questions/17821984/why-can-web-xml-welcome-file-be-located-inside-web-inf