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>
<package name="hello" extends="struts-default"> <!-- 【拦截器配置】 -->
<interceptors> <!-- 配置用户自定义的拦截器 -->
<interceptor name="helloInterceptor" class="cn.itcast.a_interceptor.HelloInterceptor"></interceptor> <!-- 自定义一个栈: 要引用默认栈、自定义的拦截器 -->
<interceptor-stack name="helloStack">
<!-- 引用默认栈 (一定要放到第一行)-->
<interceptor-ref name="defaultStack"></interceptor-ref>
<!-- 引用自定义拦截器 -->
<interceptor-ref name="helloInterceptor"></interceptor-ref>
</interceptor-stack> </interceptors> <!-- 【执行拦截器】 -->
<default-interceptor-ref name="helloStack"></default-interceptor-ref> <!-- Action配置 -->
<action name="hello" class="cn.itcast.a_interceptor.HelloAction">
<result name="success">/index.jsp</result>
</action> </package>
</struts>

action

package cn.itcast.a_interceptor;

import com.opensymphony.xwork2.ActionSupport;

/**
* Action开发测试
* @author Jie.Yuan
*
*/
public class HelloAction extends ActionSupport{ public HelloAction() {
System.out.println("1. Action实例创建了");
} @Override
public String execute() throws Exception {
System.out.println("3. 执行了请求处理的方法: execute");
return super.execute();
}
}

Interceptor

package cn.itcast.a_interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor; /**
* 自定义拦截器
* @author Jie.Yuan
*
*/
public class HelloInterceptor implements Interceptor{ // 启动时候执行
public HelloInterceptor(){
System.out.println("创建了拦截器对象");
} // 启动时候执行
@Override
public void init() {
System.out.println("执行了拦截器的初始化方法");
} // 拦截器业务处理方法 (在访问action时候执行? 在execute之前执行?)
@Override
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("2. 执行Action之前"); // 调用下一个拦截器或执行Action (相当于chain.doFilter(..)
// 获取的是: execute方法的返回值
String resultFlag = invocation.invoke(); System.out.println("4. 拦截器,业务处理-结束" + resultFlag); return resultFlag;
} @Override
public void destroy() {
System.out.println("销毁....");
} }

Struts拦截器(转)的更多相关文章

  1. [置顶] 使用struts拦截器+注解实现网络安全要求中的日志审计功能

    J2EE项目中出于安全的角度考虑,用户行为审计日志功能必不可少,通过本demo可以实现如下功能: 1.项目中记录审计日志的方法. 2.struts拦截器的基本配置和使用方法. 3.struts拦截器中 ...

  2. 利用Struts拦截器限制上传图片的格式和大小

    在这之前 Struts的一个核心功能就是大量的拦截器,既然是框架,那么自然也就贴心地为我们准备好了各种常用的功能,比如这里即将讨论的如何限制上传图片的格式和大小.那么既然是使用Struts已经写好的拦 ...

  3. Struts拦截器设置完的值为什么在页面取不到

    Struts拦截器设置完的值为什么在页面取不到. ActionContext ac = (ActionContext) invocation.getInvocationContext(); ac.pu ...

  4. struts 拦截器 Interceptor

         拦截器是AOP中的概念,它本身是一段代码,可以通过定义“织入点”,来指定拦截器的代码在“织入点”的前后执行,从而起到拦截的作用.正如上面 Struts2的Reference中讲述的,Stru ...

  5. struts拦截器实现原理

    图1: 上1来源于Struts2官方站点,是Struts 2 的整体结构. 一个请求在Struts2框架中的处理大概分为以下几个步骤 1 客户端初始化一个指向Servlet容器(例如Tomcat)的请 ...

  6. struts拦截器

    struts中的拦截器相当于过滤器的作用 一在struts.xml中配置拦截器或拦截器栈 <interceptors>!--全部的拦截器 <interceptor name=&quo ...

  7. (转)Struts 拦截器

    一.拦截器是怎么实现: 实际上它是用Java中的动态代理来实现的 二.拦截器在Struts2中的应用 对于Struts2框架而言,正是大量的内置拦截器完成了大部分操作.像params拦截器将http请 ...

  8. struts——拦截器

    什么是拦截器 拦截器(Interceptor)是Struts 2的一个强有力的工具,有许多功能都是构建于它之上,如国际化(前两篇博客介绍过).转换器,校验等. 拦截器是动态拦截Action调用的对象. ...

  9. Struts拦截器使用

    创建拦截器java程序 package cn.itcast.oa.util; import com.opensymphony.xwork2.ActionInvocation; import com.o ...

  10. 六 Struts 拦截器、OGNL表达式

    一.OGNL表达式1.概念:是表达式语言,专门用来访问对象取值用的.2.对比EL表达式使用场景: A.EL主要用在web的jsp页面取值 B.OGNL适用以下环境 1.java程序中 2.在页面使用( ...

随机推荐

  1. win10系统中virtualbox无法安装64位系统

    win10系统中virtualbox无法安装64位系统 先总结下如果想在虚拟机中安装64位的Linux系统,最好能满足这几个条件: 64位CPU 64位操作系统 64位的虚拟机软件 开启BIOS虚拟化 ...

  2. ci $this->load->database()

    http://pengbotao.cn/codeigniter-database.html

  3. Matplotlib基本图形之饼状图

    Matplotlib基本图形之饼状图 饼状图特点: 饼状图显示一个数据系列中各项大小与各项总和的比例饼状图的数据点显示为整个饼状图的百分比 示例代码 import os import time imp ...

  4. RAC+单节点搭建DG

    primary RAC to single standby 参考文献:RAC+单实例DATAGUARD 配置   http://blog.csdn.net/miyatang/article/detai ...

  5. BZOJ 3925 [Zjoi2015]地震后的幻想乡 ——期望DP

    我们只需要考虑$\sum F(x)P(x)$的和, $F(x)$表示第x大边的期望,$P(x)$表示最大为x的概率. 经过一番化简得到$ans=\frac{\sum T(x-1)}{m+1}$ 所以就 ...

  6. [luoguP3960] 列队(动态开点线段树)

    传送门 有splay的做法,有树状数组的做法... 最好理解的还是线段树的做法. 一开始我是这样想的,如果移动某一个人,只有当前行和最后一列会受到影响,感觉就像是个线段树,树状数组什么的. 然而接下来 ...

  7. BZOJ2707 [SDOI2012]走迷宫 【概率dp + tarjan + 高斯消元】

    题目 Morenan被困在了一个迷宫里.迷宫可以视为N个点M条边的有向图,其中Morenan处于起点S,迷宫的终点设为T.可惜的是,Morenan非常的脑小,他只会从一个点出发随机沿着一条从该点出发的 ...

  8. [JSOI2008]最大数 (线段树)

    题目描述 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值. 限制:L不超过当前数列的长度.(L>=0 ...

  9. ElasticSearch聚合入门(续)

    主要理解聚合中的terms. 参考:http://www.cnblogs.com/xing901022/p/4947436.html Terms聚合 记录有多少F,多少M { "size&q ...

  10. 洛谷P3393 逃离僵尸岛

    题目描述 小a住的国家被僵尸侵略了!小a打算逃离到该国唯一的国际空港逃出这个国家. 该国有N个城市,城市之间有道路相连.一共有M条双向道路.保证没有自环和重边. K个城市已经被僵尸控制了,如果贸然闯入 ...