shiro常用标签在jsp中的使用笔记

1、shiro标签的使用

在jsp页面头部加上shiro标签库,即可使用shiro标签

<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>

2、常用shiro标签的介绍

1)shiro:guest

用户没有身份验证时显示相应信息

2)shiro:user

用户已经经过认证/记住我登录后显示相应的信息

3)shiro:authenticated

用户已经身份验证通过,即Subject.login登录成功,不是记住我登录的

4)shiro:notAuthenticated

用户未进行身份验证,即没有调用Subject.login进行登录,包括记住我自动登录的也属于未进行身份验证。

5)shiro:pincipal

显示用户身份信息,默认调用Subject.getPrincipal() 获取,即 Primary Principal

6)shiro:hasRole

如果当前 Subject 有角色将显示 body 体内容

7)shiro:hasAnyRoles

如果当前Subject有任意一个角色(或的关系)将显示body体内容

8)shiro:lacksRole

如果当前 Subject 没有角色将显示 body 体内容

9)shiro:hasPermission

如果当前 Subject 有权限将显示 body 体内容

10)shiro:lacksPermission

如果当前Subject没有权限将显示body体内容

示例

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>

<!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>Insert title here</title>
</head>
<body>
	
	<h4>Unauthorized Page</h4>
	<br><br>
	<a href="list">back to list</a>
	<br><br>
	shiro:guest。。。<shiro:guest>显示游客访问的内容</shiro:guest>
	<br><br>
	shiro:user。。。<shiro:user>显示登录用户/记住我访问的内容</shiro:user>
	<br><br>
	shiro:authenticated。。。<shiro:authenticated>显示登录用户访问的内容(不包含记住我)</shiro:authenticated>
	<br><br>
	shiro:notAuthenticated。。。<shiro:notAuthenticated>未进行认证的用户访问显示内容</shiro:notAuthenticated>
	<br><br>
	shiro:principal。。。<shiro:principal></shiro:principal>。。。显示用户登录信息
	<br><br>
	shiro:hasRole。。。<shiro:hasRole name="user">包含user角色的用户的用户访问显示内容</shiro:hasRole>
	<br><br>
	shiro:hasAnyRoles。。。<shiro:hasAnyRoles name="user,admin">包含user或admin角色的用户的用户访问显示内容</shiro:hasAnyRoles>
	<br><br>
	shiro:lacksRole。。。<shiro:lacksRole name="admin">不包含admin角色的用户显示内容</shiro:lacksRole>
	<br><br>
	shiro:hasPermission。。。<shiro:hasPermission name="user:create">user角色拥有create权限显示内容</shiro:hasPermission>
	<br><br>
	shiro:lacksPermission。。。<shiro:lacksPermission name="user:create">user角色没有create权限显示内容</shiro:lacksPermission>
	<br><br>

</body>
</html>

效果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值