struts自定义拦截器学习
来源:互联网 发布:淘宝电子面单打印视频 编辑:程序博客网 时间:2024/06/14 02:04
//自定义拦截器
//第一步:创建一个拦截器类实现拦截器接口
/*里面有三个可以实现的方法,
destroy():销毁时执行
init():初始化时执行
intercept(ActionInvocation invocation)
在里面定义自己需要的方法
*/
package cn.itcast.interceptor;import java.awt.event.InvocationEvent;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.Interceptor;public class PermissionInterceptor implements Interceptor {public void destroy() {}public void init() {}public String intercept(ActionInvocation invocation) throws Exception {Object user = ActionContext.getContext().getSession().get("user");if(user!=null) return invocation.invoke();ActionContext.getContext().put("message", "你没有执行的权限");return "success";}}
//第二步:在配置文件中操作
/*
1)、在配置文件中注册拦截器
<interceptors>
<interceptor name="permission" class="cn.itcast.interceptor.PermissionInterceptor"/>
</interceptors>
2)、如果在配置文件中只注册自定义拦截器,那么struts2中默认拦截器就会失去效应。所以需要定义拦截器栈
<interceptor-stack name="permissionStack">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="permission"/>
</interceptor-stack>
注意:一般把默认的放在自定义的前面
3)、我们可以设置包内默认使用的拦截器:在包内所有action都能使用这个“默认”拦截器
<default-interceptor-ref name="permissionStack"></default-interceptor-ref>
注意:这个“默认”拦截器需要放在全局视图之前否则会报错
*/
<struts><constant name="struts.enable.DynamicMethodInvocation" value="false"></constant><package name="itcast" namespace="/control/employee" extends="struts-default"> <interceptors> <interceptor name="permission" class="cn.itcast.interceptor.PermissionInterceptor"/> <interceptor-stack name="permissionStack"> <interceptor-ref name="defaultStack"/> <interceptor-ref name="permission"/> </interceptor-stack> </interceptors> <default-interceptor-ref name="permissionStack"></default-interceptor-ref> <global-results> <result name="success">/WEB-INF/page/message.jsp</result> </global-results> <action name="list_*" class="cn.itcast.action.HelloWorldAction" method="{1}"> </action></package></struts>
- struts自定义拦截器学习
- struts学习(八)—自定义拦截器
- struts自定义拦截器
- Struts自定义拦截器
- Struts-自定义拦截器
- struts自定义拦截器解读
- Struts拦截器学习笔记
- Struts学习笔记---拦截器
- struts学习:拦截器配置
- struts学习:使用拦截器
- struts如何自定义一个拦截器?
- Struts第九天---自定义拦截器功能
- 自定义struts过滤器与拦截器实现
- struts自定义拦截器的编写
- struts自定义拦截器--登录权限控制
- struts自定义拦截器及其执行流程
- Struts中的拦截器以及自定义拦截器
- JavaWeb -- Struts 自定义拦截器, 登录权限拦截
- ASP+COM技术在嵌入式Webserver中的应用
- wince6.0开机自启动应用程序
- 安装Sql Server2008,Vistual Studio 2010,IIS,及相应配置的设置和遇到的问题
- 黑马程序员--java String类
- android屏幕截图
- struts自定义拦截器学习
- coderforce 1B-Spreadsheet
- hdu 1754 I hate it
- eclipse无法新建Class的问题解决方案
- 将一个小于10亿的String类型数字转换为人民币大写形式
- 关于systick的构件编写。
- 键盘消抖
- Cocos2d-x游戏中的场景滚动
- Linux关机命令