1

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.

Hakim
  • 3,225
  • 5
  • 37
  • 75

1 Answers1

5

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:


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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Does it mean that there can be multiple `welcome-file` by folder ? or multiple `web.xml` files, each specific to a certain folder ? – Hakim Jul 24 '13 at 14:00
  • 1
    Both is possible (look, why is `` called exactly like that, "*welcome file **list***"?). Multiple `web.xml` is also possible, but the others must be called `web-fragment.xml` and be included in JARs in `/WEB-INF/lib`. – BalusC Jul 24 '13 at 14:01