struts2-拦截器(一)
来源:互联网 发布:java两种多态机制 编辑:程序博客网 时间:2024/04/19 01:05
struts2-拦截器(一)
1、这里介绍的action拦截器,后续还会介绍方法拦截器。对于action拦截器,需要继承AbstractInterceptor类,并且重写intercept方法。下面是拦截器的代码:
SimpleInterceptor.java
package com.xueyoucto.random;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;import java.util.Date;/** * Created by Administrator on 2016/6/19. */public class SimpleInterceptor extends AbstractInterceptor{ private String name; public void setName(String name) { this.name = name; } @Override public String intercept(ActionInvocation actionInvocation) throws Exception { ttAction t = (ttAction)actionInvocation.getAction(); System.out.println(name+"拦截器执行开始" + new Date()); String result= actionInvocation.invoke(); System.out.println(name+"拦截器执行完毕"+ new Date()); return result; }}ttAction.java
package com.xueyoucto.random;import com.opensymphony.xwork2.ActionSupport;/** * Created by Administrator on 2016/6/19. */public class ttAction extends ActionSupport { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } public String execute(){ System.out.println(name); return ActionSupport.SUCCESS; }}Strut2.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"><struts> <constant name="struts.enable.DynamicMethodInvocation" value="false"/> <constant name="struts.devMode" value="true"/> <package name="xueyoupackage" namespace="/" extends="struts-default"> <interceptors> <interceptor name="mySimple" class="com.xueyoucto.random.SimpleInterceptor"> <param name="name">简单拦截器</param> </interceptor> </interceptors> <action name="aa"> <result>/WEB-INF/content/aa.jsp</result> </action> <action name="bb" class="com.xueyoucto.random.ttAction"> <interceptor-ref name="defaultStack"></interceptor-ref> <interceptor-ref name="mySimple"> <param name="name">修改简单拦截器名字1</param> </interceptor-ref> <result>/WEB-INF/content/bb.jsp</result> <interceptor-ref name="mySimple"> <param name="name">修改简单拦截器名字2</param> </interceptor-ref> <result>/WEB-INF/content/bb.jsp</result> </action> </package></struts>运行结果:
0 0
- struts2-拦截器(一)
- Struts2 拦截器(一)
- Struts2拦截器(一)
- struts2拦截器(一)
- Struts2拦截器篇(一)
- 框架(一)struts2--拦截器
- Struts2拦截器浅析(一)
- Struts2 拦截器详解(一)
- Struts2 拦截器详解(一)
- Struts2 拦截器详解(一)
- Struts2—拦截器(一)
- struts2中拦截器的使用(一)
- Struts2核心(一):执行线路与拦截器
- Struts2学习:拦截器篇(一)
- Struts2 源码学习(一):模拟拦截器
- 008-Struts2框架拦截器一
- struts2拦截器(六)
- Struts2拦截器(详解)
- 不同工具下的矩阵乘法速度测试
- 循环队列和链队列
- 《剑指offer》:[40]数组中只出现一次的数字
- 【c++程序】数字颠倒
- JAVA_ListIterator
- struts2-拦截器(一)
- Android视图SurfaceView的实现原理分析
- PageRank算法
- Linux大小端判断
- jquery判断checkbox是否选中及改变checkbox状态
- animation跑马灯动画实现两种方法
- java JNDI路劲配置
- jsp
- Session二