struts2的核心

*
* 地址权限控制
*/
public class CheckPrivilegeInterceptor extends AbstractInterceptor {//拦截器

 省略init和destory方法

  public String intercept(ActionInvocation invocation) throws Exception {

//ActionInvocation是Action调度者

如果拦截器堆栈中还有其他的Interceptor,那么invocation.invoke()将调用堆栈中下一个Interceptor的执行。 

2. 如果拦截器堆栈中只有Action了,那么invocation.invoke()将调用Action执行。

 

}

1、继承 AbstractInterceptor抽象类 ,并实现 intercept 方法就够了

2、在struts.xml 文件中定义拦截器(action标签外)

3、在struts.xml 文件中 的 action标签内引用 拦截器

<!--声明拦截器 -->
<interceptors>
<interceptor name="checkPrivilege" class="cn.itcast.oa.util.CheckPrivilegeInterceptor"></interceptor>

<!--重新定义默认的拦截器栈 -->

//一旦我们为某个action引用了自定义的拦截器,struts2默认的拦截器就不会再起作用,因此还需要引用默认拦截器。 
<interceptor-stack name="defaultStack">
<interceptor-ref name="checkPrivilege"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>

 

转载于:https://www.cnblogs.com/miaojinjin/p/5550984.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值