如何设置 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 页面删除了。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM