首页 > 其他 > 详细

struts2的核心

时间:2016-06-01 21:23:54      阅读:242      评论:0      收藏:0      [点我收藏+]

*
* 地址权限控制
*/
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>

 

struts2的核心

原文:http://www.cnblogs.com/miaojinjin/p/5550984.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!