struts2的自定义拦截器和配置
来源:互联网 发布:单片机开发论坛 编辑:程序博客网 时间:2024/05/16 08:44
1.编写拦截器,需要实现Interceptor接口,实现接口中的三个方法。 * interceptor接口有很多的实现类,编写最简单的方式就是继承AbstractInterceptor实现类。 * 代码例如: public String intercept(ActionInvocation invocation) throws Exception { User user = (User) ServletActionContext.getRequest().getSession().getAttribute("existUser"); if(user == null){ ActionSupport as = (ActionSupport) invocation.getAction(); as.addActionError("您没有登陆!"); return as.LOGIN; }else{ // 放行 return invocation.invoke(); } } * 需要在struts.xml中进行拦截器的配置,配置一共有两种方式: > 第一种方式 * 在<package>包中定义拦截器,出现在<package>包的上方 <interceptors> <interceptor name="loginInterceptor" class="cn.itcast.interceptor.LoginInterceptor"></interceptor> </interceptors> * 在某个action中引入拦截器 <interceptor-ref name="loginInterceptor"></interceptor-ref> * 注意:如果引入了自己定义的拦截器,那么Struts2框架默认的拦截器就不会再执行了,所以需要引入Struts2默认的拦截器。 <interceptor-ref name="defaultStack"></interceptor-ref> > 第二种方式 * 在<package>包中定义拦截器的时候,自己直接定义一个拦截器栈 <interceptors> <interceptor name="loginInterceptor" class="cn.itcast.interceptor.LoginInterceptor"/> <interceptor-stack name="myStack"> <interceptor-ref name="loginInterceptor"/> <interceptor-ref name="defaultStack"/> </interceptor-stack> </interceptors> * 在Action包中引入自己定义的拦截器栈 <action name="book_*" class="cn.itcast.action.BookAction" method="{1}"> <interceptor-ref name="myStack"/> </action>
0 0
- struts2的自定义拦截器和配置
- Struts2 自定义拦截器配置和使用
- struts2中拦截器的全局拦截和自定义拦截
- struts2中自定义拦截器的配置
- struts2配置自定义拦截器
- Struts2拦截器的配置和使用
- Struts2的自定义拦截器
- Struts2的自定义拦截器
- struts2的自定义拦截器
- Struts2的自定义拦截器
- Struts2的自定义拦截器
- Struts2配置拦截器和拦截链
- Struts2配置拦截器和拦截链
- 如何配置自定义struts2拦截器
- struts2自定义拦截器注解配置方法
- Struts2的拦截器、自定义拦截器、Struts2 验证机制
- struts2拦截器的配置
- struts2 拦截器的配置
- xib_storyboard的使用
- HDU 3400 Line belt
- 卷积神经网络(CNN)
- python—解决“Unable to find vcvarsall.bat”错误
- linux 资源
- struts2的自定义拦截器和配置
- TextView+Fragment实现底部导航栏
- centos6.5 openjdk https/ssl兼容性错误ECKeyPairGenerator.generateKeyPair
- 使用一维数组进行简单排序(冒泡法)
- 一些小Bug,技巧以及注意事项
- 计算从1到n整数中K出现的次数
- iOS——UINavigationController
- 项目7.3 计算一周工资
- iOS 之美:iOS Delegate 使用五步曲