问题描述
项目之前在Jetty下运行的,http://ip:port/context/原本是进入到Controller的@RequestMappin(“/”)方法的,但部署到Tomcat下,总是跳转到index.jsp
问题分析
1、访问应用的其他路径都正常,这个请求压根没有得到DispatchServlet处理,默认返回index.jsp,应该是tomcat配置问题
2、那是不是应用的web.xml里配置的不对,但看了应用的web.xml配置,并没有配welcome-file-list
3、那是不是tomcat自身conf下面的web.xml配置在起作用
<!-- If you define welcome files in your own application's web.xml -->
<!-- deployment descriptor, that list *replaces* the list configured -->
<!-- here, so be sure to include any of the default values that you wish -->
<!-- to use within your application. -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
意思是:如果应用的web.xml没有配welcome-file-list,那就会按照这里的默认配置走。。。
于是乎,我们直接注释掉,再访问,哇哦,果然可以了,我淦~
总结
虽然是个小问题,但最难发现,观察现象,定位原因范围,一点点测试排查分析,分享一下希望对大家有所帮助~