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

喜欢而已 提交于 2019-12-07 01:43:58

问题


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?


回答1:


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.




回答2:


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




回答3:


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:

  • http://technologicaloddity.com/2010/03/25/spring-welcome-file-without-redirect/
  • http://wiki.metawerx.net/wiki/HowToUseAServletAsYourMainWebPage

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


来源:https://stackoverflow.com/questions/1489219/tomcat-6-can-welcome-page-be-inside-web-inf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!