Java Web项目中如何设置项目默认打开的页面

在我们的web项目中的web/WEB-INF目录下有一个web.xml文件 , 在这个xml文件中可能有如下代码

<welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.jsp</welcome-file>  
</welcome-file-list>

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

但是有的有的时候 , 我们及时添加了这样的代码 , 也无法将其设置为默认页面 , 这是为什么呢?

这是因为tomcat服务器本身就已经设置了默认页面 , 这个文件是在你安装的tomcat目录的tomcat\conf\web.xml下 ,
打开这个文件之后 , 我们找到这样的一段代码 :

<welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

这样每次我们在项目打开时首先默认访问的页面就是index.jsp , 其次是 index.html , 以此类推 , 直到在项目目录下找到为止 , 因此我们如果要设置项目默认打开我们想要打开的页面 , 比如说 登录页面 , 每次访问都得先进行登录 , 我们就可以做一个登录页面 login.jsp , 然后在这个web.xml文件夹中添加一段代码 :

<welcome-file-list>
        <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-list>

这样就可以访问我们想要打开的默认页面了 , 很多人通常只注意到了自己项目下的web.xml文件 , 却忽略了tomcat服务器本身的默认页面设置 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值