这个java的web项目的架构是spring+struts2+hibernate
设置了欢迎页index.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>跳转主页</title>
</head>
<body>
<%
//获取项目名称
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
//方便后面在JSP里用EL取值符取地址
application.setAttribute("basePath",basePath);
response.sendRedirect(path + "/home/homeAction_home.action");
%>
</body>
</html>
希望通过这个index.jsp界面通过action跳转到我的访问主页
发现虽然在web.xml配置了欢迎页,但直接通过IP访问的话还是会被shiro拦截
首先可以确定的是被shiro拦截了,那应该是shiro的过滤器配置没有写对
applicationContext-shiro.xml
<!--
shiro 提供的过滤器:
anon 匿名访问过滤器,配置哪些资源不需要拦截,直接放行访问
authc 认证过滤器,配置哪些资源需要进行认证
举例1:
/index.jsp* = anon
左侧: 访问index.jsp或者如index.jsp?id=100,使用anon过滤器
右侧:配置anon匿名访问过滤器,不进行认证校验
举例2:
/** = authc
左侧:表示其他所有资源
右侧:除了匿名访问过滤器放行的资源,其他资源都需要使用authc认证过滤器进行登陆认证判断
--!>
<property name="filterChainDefinitions">
<value>
/index.jsp* = anon
/home/homeAction_home.action = anon
/user/userAction_* = anon
/css/** = anon
/images/** = anon
/js/** = anon
/** = authc
</value>
</property>
其中我对我的欢迎页面index.jsp设置的访问权限是不需要拦截
后来发现我通过IP访问时并没有进入到index.jsp,而是在直接通过IP访问时被拦截了
因为里面的CSS和IMG都需要index.jsp中所存的basePath路径,所以显示异常
但跳转的页面的确是被拦截的意思
<!-- 认证失败时候对应的页面地址。如果用户没有登陆,跳转到登陆页面 -->
<property name="loginUrl" value="/home/homeAction_homeT.action" />
但为什么会被拦截呢?
https://blog.csdn.net/TYOUKAI_/article/details/78480359在这篇博客中讲到shiro的Filter的优先级会高于欢迎页
所以在我们访问欢迎页前shiro的Filter就会把我们的请求拦截
所以我在对shiro的配置文件中增加了 / = anon
即对根目录的访问不进行拦截
<property name="filterChainDefinitions">
<value>
/index.jsp* = anon
/home/homeAction_home.action = anon
/user/userAction_* = anon
/ = anon <!-- 不对根目录的访问进行拦截 --!>
/css/** = anon
/images/** = anon
/js/** = anon
/** = authc
</value>
</property>
问题解决。