Struts2 配置过滤器
来源:互联网 发布:老滚5捏脸数据导入 编辑:程序博客网 时间:2024/04/28 11:26
Struts2 配置过滤器,他跟Result是一个地位,也是在action里面可以配置的
<struts> <package name="test" extends="struts-default"> <interceptors>这是自定义的过滤器 <interceptor name="myInter" class="com.interceptor.myInterceptor"></interceptor> <interceptor-stack name="defaultStack"> <interceptor-ref name="token" /> <interceptor-ref name="defaultStack"></interceptor-ref>将自定的过滤器添加到栈里面,不将这个加到栈里面,会出现前段的参数传递不过来 <interceptor-ref name="myInter"></interceptor-ref> </interceptor-stack><!-- 这个是我自己定义一个栈,将默认的栈放到我自己定义的栈中 <interceptor-stack name="myStack"> <interceptor-ref name="token" /> <interceptor-ref name="defaultStack" /> <interceptor-ref name="myInter" /> </interceptor-stack> --> </interceptors> </package></struts>
接受请求的ACtion类
package com.act;import javax.interceptor.Interceptor;import org.apache.struts2.convention.annotation.Action;import org.apache.struts2.convention.annotation.InterceptorRef;import org.apache.struts2.convention.annotation.ParentPackage;import org.apache.struts2.convention.annotation.Result;import com.opensymphony.xwork2.ActionSupport;@ParentPackage("test")public class FilterTestAct extends ActionSupport{ private String msg; private Integer id; private String money; private String msg1; @Override//我是用的是默认的defaultStack这个所以我注释了/*,interceptorRefs={@InterceptorRef("myStack")}*/这句代码 @Action(value="test",results={@Result(location="index.jsp")}/*,interceptorRefs={@InterceptorRef("myStack")}*/) public String execute() throws Exception { // TODO Auto-generated method stub msg="Action+done!"+id; return SUCCESS; } @Action(value="pay",results={@Result(location="index.jsp"),@Result(name="invalid.token" ,location="err.jsp")}/*,interceptorRefs={@InterceptorRef("myStack")}*/) public String pay(){ msg1=money; return SUCCESS; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getMoney() { return money; } public void setMoney(String money) { this.money = money; } public String getMsg1() { return msg1; } public void setMsg1(String msg1) { this.msg1 = msg1; }}
package com.interceptor;import java.util.Random;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;public class myInterceptor extends AbstractInterceptor{private Random random=new Random();private int ss=5000; @Override public String intercept(ActionInvocation arg0) throws Exception { long beginTimer=System.currentTimeMillis(); Thread.currentThread().sleep(random.nextInt(5)*1000); //拦截通过 String relcode=arg0.invoke(); System.out.println("处理时间"+(System.currentTimeMillis()-beginTimer));//用来判断拦截是否给通过 return relcode;}}
然后是传到过滤器里面:
在invoke上面的打印会在action之前处理
在invoke下面的打印会在action之后处理
0 0
- struts2过滤器配置
- Struts2 配置过滤器
- Struts2过滤器配置
- struts2配置定义过滤器无效
- struts2.5过滤器配置篇
- 配置struts2的核心过滤器
- 配置web.xml,配置Struts2的过滤器
- struts2.2.3 配置中文乱码拦截过滤器
- struts2.2.3 配置中文乱码拦截过滤器
- struts2.2.3 配置中文乱码拦截过滤器
- struts2.2.3 配置中文乱码拦截过滤器
- struts2 过滤器
- struts2 过滤器
- struts2 过滤器
- struts2 过滤器
- struts2 过滤器
- struts2 过滤器
- Struts2过滤器
- java 获取ip
- Tiledmap基本使用教程
- 连接器/ Python连接池
- java 23种设计模式及具体例子
- text/html和text/plain的区别
- Struts2 配置过滤器
- 蒙特卡罗方法入门
- AFN 的使用问题
- Github contributions 故障处理
- HTML文件和SHTML文件的区别
- 华为oj 字符串最后一个单词的长度
- 基类和派生类的关系
- Spring事务管理
- 【XMPP协议】开发Android即时通讯APP之了解XMPP(一)