[英]index.jsp file opens even when the <welcome-file-list> is not defined
我在Eclipse Luna中编写了一个简单的动态Web项目。 在web.xml页面中,我删除了默认的welcome-file-list
标记。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>indextest</display-name>
</web-app>
但是,即使在我从web.xml
删除了标签welcome-file-list
之后,url http:// localhost:8080 / indextest仍然指向'WEB-INF'下的index.jsp
。 它如何指向index.jsp
页面虽然web.xml
没有welcome-file-list
?
如果没有提供欢迎列表,则容器将尝试按定义的顺序加载以下文件:
更新:关于tomcat
如果应用程序中未提供web.xml,则会将Tomcat的默认web.xml($ CATALINA_HOME / conf / web.xml)提供给应用程序。 此部署描述符包含以下行:
<!-- -->
<!-- If you define welcome files in your own application's web.xml -->
<!-- deployment descriptor, that list *replaces* the list configured -->
<!-- here, so be sure to include any of the default values that you wish -->
<!-- to use within your application. -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
这就是默认情况下显示index.jsp的原因
如果您正在使用Tomcat 7实例,并且未指定welcome-file-list,则容器(tomcat)将查看其默认值,即tomcat实例中的/conf/web.xml。
这些是:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
我建议不要在tomcat默认值中更改任何内容,因为您的Web应用程序不应该依赖于运行它的容器。 相反,您应该在自己的web.xml中定义自己的welcome-file-list。 希望这可以帮助!
如果更改文件名,默认文件将调用index.jsp
然后它将找不到index.jsp
,您可以获得预期的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.