使用 welcome-file-list 设置欢迎界面

简介

在开发中用<welcome-file-list/>设置欢迎界面,始终报404,参考了网上所有现有的做法仍旧不能解决,最终发现失败的原因是因为请求被拦截。

配置说明

设置index.jsp页面:写一个简单的index.jsp页面,内容如下

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>"******"</title>
<style type="text/css">
body {
    background-color: #ffffff;
    background-image: url(images/bg.jpg);
    background-repeat: repeat-x;
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
div,td {
    font-size: 12px;
}
#divContent {
    border: 1px solid #0165b3;
    padding: 12px;
    background-color: #f5fff0;
    line-height: 150%;
}
#shadow1 {
    background-color: #666666;
    filter: Alpha(Opacity=55);
}
#shadow2 {
    background-color: #666666;
    filter: Alpha(Opacity=35);
}
#shadow3 {
    background-color: #666666;
    filter: Alpha(Opacity=15);
}
</style>
alert("hello");
</head>

<body>
   <table width="100%" border="10" cellspacing="0" cellpadding="0">
       <tr>
          <td height="346" valign="top"><img src="./imag/image_1.jpg" width="938" height="346" /></td>
       </tr>
   </table>
<form action="" name=""></form>
</body>
</html>

将index.jsp放置于/WebContent/ 目录之下。上述<td/>中关联了一张图片,即./imag/image_1.jpg。未知位于/WebContent/imag/目录下,如图

 

在web.xml中配置welcome-file-list,如下

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

发布以后,应该在tomcat的/webapps/projectName/目录下有index.jsp文件,即

如果正常,在tomcat启动的时候在IE中输入 http://ip:port/projectName 就应该能够正常的显示index页面,但是我这里却一直报404.

我用 http://ip:port/projectName/index.jsp发现能够打开jsp页面,只是用工程名不行,于是我觉得应该是哪里把请求给拦截了,于是排查了web.xml文件,发现其中Dispatch中对/*就行拦截,即所有请求都被拦截了,如图

 <!-- <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>-->

通过上述代码可以看到dispatcher这个servlet拦截了所有的请求,包括http://ip:port/projectName请求,于是在下将该代码注释掉再次启动,世界一片清平。。。。

希望上述分析对读者有益。

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值