shiro标签在html页面的使用

1.shiro标签在jsp页面的使用:

直接引入标签库:<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>

 2.shiro标签在html页面的使用:

html不同于jsp,属于静态页面,只有html原生标签库,如果想在html页面使用shiro标签,需要搭配thymeleaf来进行引用

2.1导入依赖

 2.2springmvc配置文件注册视图解析器及方言解释器

<!--使用thyme leaf-->
<!--视图解析器-->
<bean id="templateResolver" class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">
    <property name="templateMode" value="HTML"></property>
    <property name="cacheable" value="false"/>
    <property name="characterEncoding" value="UTF-8"/>
</bean>

<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
    <property name="templateResolver" ref="templateResolver"></property>
    <property name="additionalDialects">
        <set>
            <!--方言解释器-->
            <bean class="at.pollux.thymeleaf.shiro.dialect.ShiroDialect"/>
        </set>
    </property>
</bean>

<bean id="viewResolver" class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
    <property name="templateEngine" ref="templateEngine"/>
    <property name="characterEncoding" value="UTF-8"/>
</bean>

2.3页面使用

<!DOCTYPE html>
<html lang="en"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2 shiro:authenticated><a>已认证</a></h2>
<h2 shiro:guest=""><a>游客访问</a></h2>
<shiro:authenticated><a>已认证</a></shiro:authenticated>
<shiro:guest><a>游客访问</a></shiro:guest>
<shiro:hasAnyPermissions name="USER_QUERY"><a>查询</a></shiro:hasAnyPermissions>
</body>
</html>

2.4效果

  • 10
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,Shiro权限管理器可以根据realm的授权信息判断是否拥有某个权限,如果没有权限则跳转到响应页面。如果需要放行某个页面,则可以在Shiro的配置文件中进行相应的配置。具体步骤如下: 1. 在Shiro的配置文件中,找到`<shiro:filter>`标签,添加一个新的`<shiro:filter>`标签,例如: ```xml <shiro:filter> <shiro:filter-name>myFilter</shiro:filter-name> <shiro:filter-class>com.example.MyFilter</shiro:filter-class> </shiro:filter> ``` 2. 在`<shiro:filter>`标签中,设置`<shiro:perms>`标签,指定需要放行的页面和权限,例如: ```xml <shiro:filter> <shiro:filter-name>myFilter</shiro:filter-name> <shiro:filter-class>com.example.MyFilter</shiro:filter-class> <shiro:perms> /index.html = myPermission </shiro:perms> </shiro:filter> ``` 上述配置表示,放行`/index.html`页面,并且需要具有`myPermission`权限。 3. 在Shiro的配置文件中,找到`<shiro:filter-mapping>`标签,添加一个新的`<shiro:filter-mapping>`标签,例如: ```xml <shiro:filter-mapping> <shiro:filter-name>myFilter</shiro:filter-name> <shiro:url-pattern>/index.html</shiro:url-pattern> </shiro:filter-mapping> ``` 上述配置表示,将`myFilter`过滤器映射到`/index.html`页面。 通过上述配置,可以实现对某个页面的放行。需要注意的是,如果需要放行的页面需要具有多个权限,则可以使用逗号分隔多个权限,例如: ```xml <shiro:perms> /index.html = myPermission1, myPermission2 </shiro:perms> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值