TomCat 6:欢迎页面在WEB-INF里面吗?

时间:2009-09-28 20:34:01

标签: tomcat servlets web.xml

我正在按照这个例子来获得Spring up&正在运行:http://static.springsource.org/docs/Spring-MVC-step-by-step/part2.html

他们所做的是移动WEB-INF中的所有.jsp文件,以阻止用户直接访问它们......到目前为止一切顺利。但是servlet有一个index.jsp的欢迎页面,当它在WEB-INF目录中移动时,我得到错误。我无法确定Tomcat 6是否应该允许欢迎页面在WEB-INF内?

3 个答案:

答案 0 :(得分:7)

WEB-INF中的任何内容都不能直接访问,但必须首先通过其他内容(通常是servlet),然后将请求内部转发到WEB-INF资源。

答案 1 :(得分:3)

我正在尝试相同的教程。本教程没有说明这一点,但我将web.xml中的值从“index.jsp”更改为“/WEB-INF/jsp/index.jsp”。

答案 2 :(得分:1)

我使用这种技术(适用于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>

所以您不再需要redirect.jsp

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

在非WEB-INF目录!!

这里有两个博客采用相同的技术:

更新来自SRV.9.10 Welcome Files文档的Servlet API 2.4部分^

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