修改配置web.xml文件
<welcome-file-list>
<welcome-file>login.html</welcome-file>
<welcome-file>login.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
在javaweb项目启动时,就会在项目目录下面自上而下逐一查找文件,如果找到了如上6个中的某一个文件,则以这个文件为welcom-file,也就是这个项目的默认页面。
不生效怎么办?
修改本地tomcat的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>
注意看它上面的注释
<!-- ==================== Default Welcome File List ===================== -->
<!-- When a request URI refers to a directory, the default servlet looks -->
<!-- for a "welcome file" within that directory and, if present, to the -->
<!-- corresponding resource URI for display. -->
<!-- If no welcome files are present, the default servlet either serves a -->
<!-- directory listing (see default servlet configuration on how to -->
<!-- customize) or returns a 404 status, depending on the value of the -->
<!-- listings setting. -->
<!-- -->
<!-- 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. -->
大致意思就是:项目启动会先读取本配置文件,但是如果自己配置了会覆盖本文件
我的tomcat版本是9.0是这一种情况
如果你的不生效就修改tomcat的配置文件,有可能是你的tomcat版本不会覆盖,所以不会生效