一、Shiro中的JSP标签(红色为常用)
标签名称 | 标签条件(均是显示标签内容) |
<shiro:authenticated> | 登录之后 |
<shiro:notAuthenticated> | 不在登录状态时 |
<shiro:guest> | 用户在没有RememberMe时 |
<shiro:user> | 用户在RememberMe时 |
<shiro:hasAnyRoles name="abc,123" > | 在有abc或者123角色时 |
<shiro:hasRole name="abc"> | 拥有角色abc |
<shiro:lacksRole name="abc"> | 没有角色abc |
<shiro:hasPermission name="abc"> | 拥有权限资源abc |
<shiro:lacksPermission name="abc"> | 没有abc权限资源 |
<shiro:principal> | 显示用户身份名称 |
<shiro:principal property="username"/> | 显示用户身份中的属性值 |
二、使用步骤
1):在jsp中引入shiro标签库
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
2)标签是否拥有权限进而显示操作按钮
如:
其中/loginOut为已配置的退出配置在ini文件中如下配置。
#当请求/loginOut,会被logout捕获并清除session
/loginOut=logout
#登出之后重定向的页面
logout.redirectUrl=/login