关于web.xml的welcome-file-list 配置与tomcat的关系:
2018年04月18日 10:17:13 守望dfdfdf 阅读数:377 标签: welcome-file-list 更多
版权声明:本文为博主原创文章,转载请注明文章链接。 https://blog.csdn.net/xiaoanzi123/article/details/79985029
先介绍下我的本地:用的tomcat7。web.xml中配置如下:
- <welcome-file-list>
- <welcome-file>system/index.do</welcome-file>
- </welcome-file-list>
系统启动初始化,访问http://localhost:8080/项目名 ,就会访问初始的system/index.do,然后被spring拦截,跳转到controller,在controller中跳转到index.jsp。我本地运行没有问题,index.jsp正常访问到 。注意:index.jsp是放在WEB-INF下的view目录下的。具体参见下图:
现在我把项目部署到开发环境后,访问http://ip/项目名, 一直都是404,这让我很纳闷。由于之前开发环境的tomcat各种配置被更改过,我把server.xml和context.xml全部换成初始状态的xml文件还是不行。但是直接在浏览器地址栏访问项目下的js文件是能够访问到的。说明项目没问题。这时注意到
- <welcome-file-list>
- <welcome-file>system/index.do</welcome-file>
- </welcome-file-list>
于是决定弃用systemController,改为:
- <welcome-file-list>
- <!-- <welcome-file>system/index.do</welcome-file> -->
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
由于index.jsp在WEB-INF下的view目录下,而WEB-INF下的资源是受到保护的,不能直接访问,于是把index.jsp移动到webapp目录下。再次访问就可以了。
至于原因,我猜测是tomcat版本的原因。不然不会发生我本地可以访问而开发环境访问不到的问题。我本地tomcat7,开发环境tomcat6。
<!-- 说明:开发环境为tomcat6,项目启动初始访问 http://ip/项目名 返回404,找不到system/index.do。 解决办法:把view目录下的index.jsp移动到webapp目录下,此时项目启动访问首页不用再经过systemcontroller了。直接访问webapp目录下的index.jsp -->
关于这个问题,也查到一些文章,大家表达的意思大致都是一样的,他们都是新建一个同名的空文件解决的,和我的处理方式不同,但都是一个原因。参见这篇为例:https://blog.csdn.net/guoquanyou/article/details/6590141