如何设置 web 项目打开的默认页面

引言

我们在创建 Web 项目启动 Tomcat 会自动打开一个默认 index.jsp 页面,这个页面是创建 Web 项目时就自动生成的。那么,如何设置 web 项目打开的这个的默认页面,改为自己的默认启动页面呢?

修改配置 web.xml 文件

在 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>

在 tomcat 启动项目时,就会在项目目录下面自上而下逐一查找文件,如果找到了如上 6 个中的某一个文件,则以这个文件为 welcom-file,也就是这个项目的默认页面。

如果我们只需要一个打开默认页面,那么就只配置一个即可,如下:

<welcome-file-list>
        <welcome-file>login.html</welcome-file>
</welcome-file-list>

这时,就可以把项目中自动生成的 index.jsp 页面删除了。

作者:Binge
本文版权归作者和博客园共有,转载必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/binbingg/p/13830027.html