Mr. Boy
Mr. Boy

Reputation: 63720

TomCat 6: can welcome page be inside WEB-INF?

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?

Upvotes: 7

Views: 5998

Answers (3)

gavenkoa
gavenkoa

Reputation: 48753

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

Upvotes: 1

Sam
Sam

Reputation: 31

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

Upvotes: 3

skaffman
skaffman

Reputation: 403461

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.

Upvotes: 7

Related Questions