Interceptor拦截器无法拦截根目录的解决方法

今天发现了一个bug,首页home.jsp的某一个值是通过拦截器拦截所有页面,然后赋值的,然而我们的首页是通过index.jsp直接引用首页home.jsp代码(如下),拦截器无法拦截。

<%@ include file="./WEB-INF/jsp/home.jsp" %>

首先,第一个解决方法就是,将首页的引用文件改为跳转即可

<html>
<head><meta http-equiv="refresh" content="0;URL=/"></head>
<body>
<h2></h2>
</body>
</html>

第二个方法就是,在web.xml中配置

  <welcome-file-list>
  	<welcome-file></welcome-file>
  </welcome-file-list>

这个配置标识根路径不要web服务器来处理,而是由程序自身来处理。这时,index.jsp也就不起作用了。
然后在controller中写一个路径为"/"的映射页面即可。

PS:相关知识点
web.xml 中没有配置任何有关欢迎页的信息等效于如下配置:这个会由Web容器最先访问!

//-未指定欢迎页时,缺省等于如下配置。这个应该不同的Web服务器可以设置,但大多数都如此-

<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服务器自动配置,则可以添加

  <welcome-file-list>
  	<welcome-file></welcome-file>
  </welcome-file-list>

版权声明:本文为u013425438原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。