7

I'm following this example to get Spring up & running: http://static.springsource.org/docs/Spring-MVC-step-by-step/part2.html

What they do is move all .jsp files inside the WEB-INF, to stop users accessing them directly... so far so good. However the servlet has a welcome page of index.jsp, and when this is moved inside the WEB-INF dir I get errors. I can't determine if Tomcat 6 should allow the welcome page to be inside WEB-INF or not?

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589

3 Answers3

7

Nothing inside WEB-INF can be directly accessed, but must first pass through something else (usually a servlet), which then forwards the request internally to the WEB-INF resource.

skaffman
  • 398,947
  • 96
  • 818
  • 769
3

I am trying the same tutorial. The tutorial doesn't say this but I changed the value in my web.xml from "index.jsp" to "/WEB-INF/jsp/index.jsp".

Sam
  • 31
  • 1
1

I use such technique (which work for Servlet API >= 2.4):

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
    <url-pattern>/index.htm</url-pattern>    <<==  *1*
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.htm</welcome-file>   <<== *2*
</welcome-file-list>

so you no longer need redirect.jsp with:

<% response.sendRedirect("/myproject/MyAction.action"); %>

in non-WEB-INF directory!!

Here two blogs with same technique:

UPDATE From SRV.9.10 Welcome Files section of Servlet API 2.4 documentation^

The purpose of this mechanism is to allow the deployer to specify an ordered
list of partial URIs for the container to use for appending to URIs when there is a
request for a URI that corresponds to a directory entry in the WAR not mapped to
a Web component. This kind of request is known as a valid partial request.

The use for this facility is made clear by the following common example: A
welcome file of `index.html' can be defined so that a request to a URL like
host:port/webapp/directory/, where `directory' is an entry in the WAR that is
not mapped to a servlet or JSP page, is returned to the client as `host:port/
webapp/directory/index.html'.
gavenkoa
  • 45,285
  • 19
  • 251
  • 303
  • This answer assumes Spring, but nothing in the question indicates that OP is using Spring. – BalusC Mar 21 '13 at 15:59
  • Why? It based on `SRV.9.10 Welcome Files` section of Servlet API 2.4 documentation. There are no *Spring* keyword... – gavenkoa Mar 22 '13 at 12:23
  • `dispatcher` on `/` is classic Spring. – BalusC Mar 22 '13 at 12:24
  • Yes I copy part from my Spring project (*as real word example*). But you can do this with any servlets and any servlet mapping URL patterns... – gavenkoa Mar 22 '13 at 12:27
  • Oh? Alter the answer accordingly then to achieve it without any 3rd party framework. As far as we know, this is not possible without a servlet which forwards to the `/WEB-INF` resource, like as Spring's dispatcher one, exactly as already answered by skaffman for long. – BalusC Mar 22 '13 at 12:30
  • Ok, I become understand what you mean )) But in term of Servlet documentation *pages* are not *files* but a way to remap directory entries to another URLs... – gavenkoa Mar 22 '13 at 12:36