自定义拦截器
来源:互联网 发布:arp s ip mac 编辑:程序博客网 时间:2024/05/16 04:39
struts自定义拦截器可以继承AbstractInterceptor,或者实现Interceptor接口
实现接口要重写三个方法。
public class ValidLoginIntercept implements Interceptor{public void destroy() {}public void init() {}public String intercept(ActionInvocation arg0) throws Exception {return null;}}
下面是这次的练习代码
package com.interceptor;import java.util.Map;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;//自定义拦截器public class ValidLoginIntercept extends AbstractInterceptor {@Overridepublic String intercept(ActionInvocation arg0) throws Exception {Map session=arg0.getInvocationContext().getSession();String username=(String)session.get("sessionusername");if(username==null){return Action.INPUT;}else{return arg0.invoke();}}}
struts.xml的配置
<!-- 拦截器的使用 --><interceptors><!-- 定义拦截器 --><interceptor name="validLoginIntercept" class="com.interceptor.ValidLoginIntercept" ></interceptor><interceptor-stack name="invalLogin"><interceptor-ref name="defaultStack"></interceptor-ref><interceptor-ref name="validLoginIntercept"></interceptor-ref></interceptor-stack></interceptors> <action name="loginAction2" class="com.struts.LoginAction" method="login"><!-- 在action中调用拦截器 --><interceptor-ref name="defaultStack"></interceptor-ref><result name="success">/taglogin.jsp</result><result name="failed">/taglogin.jsp</result><result name="input">/taglogin.jsp</result></action>
- struts2 自定义拦截器
- 自定义拦截器(转)
- Struts2自定义拦截器
- 自定义拦截器
- Struts2自定义拦截器
- strust2自定义拦截器
- 自定义时间拦截器
- struts2自定义拦截器
- Struts2自定义拦截器
- 拦截器(自定义)
- Struts2自定义拦截器
- Struts2自定义拦截器
- 自定义异常拦截器
- Struts2自定义拦截器
- struts2自定义拦截器
- 自定义拦截器
- Struts2---自定义拦截器
- struts2自定义拦截器
- MySql循环插入数据
- configure: error: C compiler cannot create executables
- jQuery之CSS选择符 - 大于号模式 空格的作用
- jquery 之 事件处理
- OpenInventor开发环境配置
- 自定义拦截器
- VxWorks嵌入式软件保护解决方案
- 计算器小程序感悟
- 为什么要进行傅立叶变换?傅立叶变换究竟有何意义?如何用Matlab实现快速傅立叶变换?
- Javascript 数组与字典
- iis6/windows 2003下session不稳定解决办法
- Android Mms专题之:Mms源码结构
- .Net 4.0 的新 GAC
- 打印机原理