`
菜菜土人
  • 浏览: 11292 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

struts1.1拦截器

阅读更多

Usage Notes

To use SAIF, you must configure it as a Struts plugin, configure the interceptor config file, and write any interceptors you need.

Struts Plug-In Configuration

SAIF needs to be configured as a plugin in the Struts configuration file. In the plug-in configuration, the location of the interceptor configuration file needs to be defined. It should look something like this:

<plug-in className="net.sf.struts.saif.SAIFPlugin">
<set-property property="interceptor-config" value="/WEB-INF/interceptor-config.xml" />
</plug-in>

Interceptor Configuration

All interceptors are defined in interceptor-config.xml (of course it could have any name). This file contains the interceptor definitions and how they should be applied. There are two ways to declare interceptors for Struts Actions: globally and by Action. When the Action is requested, first any global interceptors will be applied, then Action-specific interceptors.

The following interceptors are included in SAIF:

Included interceptors Class Description
net.sf.struts.saif.ComponentInterceptor Performs inversion of control functionality. Sets any components the Action has defined it needs.

This is an example of an interceptor configuration file:

<interceptor-config>
<interceptor name="componentInterceptor" type="net.sf.struts.saif.ComponentInterceptor"/>
<interceptor name="testInterceptor" type="net.sf.struts.saif.TestInterceptor"/>

<default-interceptors>
<interceptor name="componentInterceptor"/>
</default-interceptors>

<action type="org.apache.struts.webapp.example.EditRegistrationAction">
<interceptor name="testInterceptor"/>
</action>
</interceptor-config>

Interceptor Implementation

Interceptors can perform actions before and after a Struts Action is called. To write an interceptor, simple implement the net.sf.struts.saif.ActionInterceptor interface and implement the beforeAction() and afterAction() methods.

This is an example of an interceptor implementation:

public class TestInterceptor implements ActionInterceptor
{
	public void beforeAction(Action action, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	{
		log.debug("beforeAction called");
	}

	public void afterAction(Action action, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	{
		log.debug("afterAction called");
	}

	private Log log = LogFactory.getLog(TestInterceptor.class);
}
          
分享到:
评论

相关推荐

    理解拦截器用于在某个方法或字段被访

    谈到拦截器,还有一个词大家应该知道——拦截器链(Interceptor Chain,在Struts 2中称为拦截器栈Interceptor Stack)。拦截器链就是将拦截器按一定的顺序联结成一条链。在访问被拦截的方法或字段时,拦截器链

    Struts2 in action中文版

    4.3 研究内建的Struts 2拦截器 67 4.3.1 工具拦截器 67 4.3.2 数据转移拦截器 67 4.3.3 工作流拦截器 69 4.3.4 其他拦截器 72 4.3.5 内建的拦截器栈 73 4.4 声明拦截器 74 4.4.1 声明独立的拦截器和拦截器栈 74 ...

    struts2讲义_吴峻申

    4.3 在Struts2中配置自定义的拦截器 53 4.3.1 扩展拦截器接口的自定义拦截器配置 54 4.3.2 继承抽象拦截器的自定义拦截器配置 56 4.3.3 继承方法拦截器的自定义拦截器配置 58 4.4 Struts2文件上传拦截器应用 61 ...

    Struts2 入门培训

    配置FILTERDISPATCHER过滤器 6 2.3. 配置STRUTS.PROPERTIES 6 2.4. 编写一个简单的ACTION类 7 2.5. STRUTS.XML配置文件 8 2.6. 在相应位置提供JSP文件 10 2.7. 转换器(CONVERTER) 10 2.8. 拦截...

    深入浅出Struts2(附源码)

    18.3 使用DataSourceInjectorInterceptor拦截器 269 18.4 小结 273 第19章定制结果类型 274 19.1 概述 274 19.2 编写一个自定义的结果类型 274 19.3 使用新的结果类型 277 19.4 小结 279 第20章 Velocity 280...

    深入Struts2的配置文件

    本部分主要介绍struts.xml的常用配置。...Struts2框架中核心组件就是Action、拦截器等,Struts2框架使用包来管理Action和拦截器等。每个包就是多个Action、多个拦截器、多个拦截器引用的集合。 ...

    struts2的总结,适合初学者

    1Mvc与servlet 1.1Servlet的优点 1、是mvc的基础,其他的框架比如struts1,struts2,...4、struts2的拦截器为mvc框架注入了全新的概念。 4Struts2入门 4.1新建一个工程为struts2 4.2修改工程的编码为utf-8 4.3导入

    深入浅出Struts 2 .pdf(原书扫描版) part 1

    18.3 使用DataSourceInjectorInterceptor拦截器 269 18.4 小结 273 第19章 定制结果类型 274 19.1 概述 274 19.2 编写一个自定义的结果类型 274 19.3 使用新的结果类型 277 19.4 小结 279 第20章 Velocity 280 ...

    J2EE实验报告

    1. 实验目的  1.1.熟悉Struts过滤器;  1.2.熟悉Struts拦截器; 2. 实验环境  2.1 MyEclipse  2.2 Window XP  2.3 MySQL

    Spring3+Hibernate4+Struts2 jar包 SSH框架

    spring 3.2.0+hibernate 4.1.6+struts2整合需要的jar包 的目录 ...文件上传,拦截器,操作的数据库是Mysql, 如果操作的数据库是oracle或者是其他, 将mysql-connector-java-5.1.20-bin.jar 改为相应的驱动包即可。

    低清版 大型门户网站是这样炼成的.pdf

    2.6.1 struts 2内建拦截器介绍 95 2.6.2 定义和使用拦截器栈 97 2.6.3 使用自定义拦截器 98 2.7 小结 100 第3章 struts 2标签库详解与ajax技术应用 103 3.1 struts 2主题与模板 103 3.2 struts 2控制标签详解 ...

    Java Web程序设计教程

    6.1.2拦截器及拦截器栈的应用 111 6.1.3自定义拦截器 115 6.2类型转换器 117 6.2.1struts2内置类型转换器 117 6.2.2引用类型的转换方式 117 6.2.3特殊对象的类型转换 118 6.2.4类型转换的错误处理 121 6.3...

    J2EE应用开发详解

    124 8.5.2 拦截器的实现原理 124 8.5.3 Struts2的内置拦截器 124 8.5.4 拦截器的配置和使用 125 8.5.5 自定义拦截器 126 8.6 一个简单的Struts2应用 130 8.7 小结 140 第9章 JSF 141 9.1 JSF技术简介 141 9.1.1 JSF...

    JAVA WEB典型模块与项目实战大全

    17.6 商业银行网上账户管理系统具体实现——工具类、校验器及拦截器  17.7小结  第18章 hibernate分页系统(hibernate 3.0)  18.1 hibernate分页系统原理  18.2 封装javabean的commons-beanutils组件  18.3...

    JAVA程序开发大全---上半部分

    8.2.3 Struts配置文件编辑器 124 8.3 Struts应用实例:登录系统 125 8.4 本章小结 133 第9章 Hibernate框架的开发及应用 134 9.1 Hibernate框架概述 134 9.1.1 O/R Mapping(对象/关系映射)技术 134 9.1.2 ...

    《MyEclipse 6 Java 开发中文教程》前10章

    10.3.3 装配拦截器和Bean 212 10.3.4 测试和运行 214 10.3.5 AOP简介和相关概念 214 10.3.6 关于java.lang.ClassCastException: $Proxy0错误的解决方法 216 10.4 开发 Spring 2.0 AOP 应用 219 10.4.1 使用aop 标签...

    Spring in Action(第二版 中文高清版).part2

    11.3.4 使用注释声明拦截器 11.4 小结 第12章 访问企业服务 12.1 从JNDI中获取对象 12.1.1 使用传统的JNDI 12.1.2 注入JNDI对象 12.1.3 在Spring 2中注入JNDI对象 12.2 发送电子邮件 12.2.1 配置邮件发送...

Global site tag (gtag.js) - Google Analytics