Struts拦截器(转)
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拦截器(转)的更多相关文章
- [置顶] 使用struts拦截器+注解实现网络安全要求中的日志审计功能
J2EE项目中出于安全的角度考虑,用户行为审计日志功能必不可少,通过本demo可以实现如下功能: 1.项目中记录审计日志的方法. 2.struts拦截器的基本配置和使用方法. 3.struts拦截器中 ...
- 利用Struts拦截器限制上传图片的格式和大小
在这之前 Struts的一个核心功能就是大量的拦截器,既然是框架,那么自然也就贴心地为我们准备好了各种常用的功能,比如这里即将讨论的如何限制上传图片的格式和大小.那么既然是使用Struts已经写好的拦 ...
- Struts拦截器设置完的值为什么在页面取不到
Struts拦截器设置完的值为什么在页面取不到. ActionContext ac = (ActionContext) invocation.getInvocationContext(); ac.pu ...
- struts 拦截器 Interceptor
拦截器是AOP中的概念,它本身是一段代码,可以通过定义“织入点”,来指定拦截器的代码在“织入点”的前后执行,从而起到拦截的作用.正如上面 Struts2的Reference中讲述的,Stru ...
- struts拦截器实现原理
图1: 上1来源于Struts2官方站点,是Struts 2 的整体结构. 一个请求在Struts2框架中的处理大概分为以下几个步骤 1 客户端初始化一个指向Servlet容器(例如Tomcat)的请 ...
- struts拦截器
struts中的拦截器相当于过滤器的作用 一在struts.xml中配置拦截器或拦截器栈 <interceptors>!--全部的拦截器 <interceptor name=&quo ...
- (转)Struts 拦截器
一.拦截器是怎么实现: 实际上它是用Java中的动态代理来实现的 二.拦截器在Struts2中的应用 对于Struts2框架而言,正是大量的内置拦截器完成了大部分操作.像params拦截器将http请 ...
- struts——拦截器
什么是拦截器 拦截器(Interceptor)是Struts 2的一个强有力的工具,有许多功能都是构建于它之上,如国际化(前两篇博客介绍过).转换器,校验等. 拦截器是动态拦截Action调用的对象. ...
- Struts拦截器使用
创建拦截器java程序 package cn.itcast.oa.util; import com.opensymphony.xwork2.ActionInvocation; import com.o ...
- 六 Struts 拦截器、OGNL表达式
一.OGNL表达式1.概念:是表达式语言,专门用来访问对象取值用的.2.对比EL表达式使用场景: A.EL主要用在web的jsp页面取值 B.OGNL适用以下环境 1.java程序中 2.在页面使用( ...
随机推荐
- Puppet 安装配置
环境说明: OS:CentOS 5.4 i386 puppetmaster 192.168.0.12 hostname: puppetmaster.info.com client ...
- 【js】--常用DOM库工具
/* 2014年3月16号 常用DOM工具库*/var DOM={}; DOM.getElesByClass=function (strClassName,context){ if(typeof st ...
- mysql replication常见错误整理
这篇文章旨在记录MySQL Replication的常见错误,包括自己工作中遇到的与网友在工作中遇到的,方面自己及别人以后进行查找.每个案例都是通过Last_IO_Errno/Last_IO_Erro ...
- 有关C语言指针访问问题
C语言指针访问问题今天有了一些理解. char *p; char *q; char k[10000]; 我之前一直以为他们两个一样用,因为之前看到说k也是一个地址,我忽略了后面的一句话,k是连续的一段 ...
- 【java基础 11】java集合框架学习
导读:本篇博客主要是从整体上了解java的集合框架,然后主要介绍几个自己在项目中用到的结构,比如说:hashtable.hashmap.hashset.arraylist等! 一.宏观预览 从宏观上看 ...
- BZOJ 3856: Monster【杂题】
Description Teacher Mai has a kingdom. A monster has invaded this kingdom, and Teacher Mai wants to ...
- 算法复习——splay+启发式合并(bzoj2733-永无乡)
题目: Description 永无乡包含 n 座岛,编号从 1 到 n,每座岛都有自己的独一无二的重要度,按照重要度可 以将这 n 座岛排名,名次用 1 到 n 来表示.某些岛之间由巨大的桥连接,通 ...
- #ifdef endif 用法
"#ifdef 语句1 程序2 #endif“ 可翻译为:如果宏定义了语句1则程序2. 作用:我们可以用它区隔一些与特定头文件.程序库和其他文件版本有关的代码. 代码举例:新建define. ...
- 洛谷 [P1939] 矩阵加速数列
矩阵快速幂模版 #include <iostream> #include <cstring> #include <cstdlib> #include <alg ...
- Eclipse 语言文件下载地址
http://www.eclipse.org/babel/downloads.php 更改配色: 安装新软件: http://eclipse-color-theme.github.com/update