`
=死神=
  • 浏览: 56821 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Struts2.0 拦截器

阅读更多

一、Struts2.0自定义的拦截器

<!-- 在不同请求之间将请求参数在不同名字件转换,请求内容不变 -->
<interceptor name="alias" class="com.opensymphony.xwork2.interceptor.AliasInterceptor" /> 
<!--  -->
<interceptor name="autowiring" class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor" /> 
<!-- 让前一个Action的属性可以被后一个Action访问,现在和chain类型的result(<result type=”chain”>)结合使用 -->
<interceptor name="chain" class="com.opensymphony.xwork2.interceptor.ChainingInterceptor" /> 
<!-- 将错误从ActionContext中添加到Action的属性字段中 -->
<interceptor name="conversionError" class="org.apache.struts2.interceptor.StrutsConversionErrorInterceptor" /> 
<!-- 自动的创建HttpSession,用来为需要使用到HttpSession的拦截器服务 -->
<interceptor name="createSession" class="org.apache.struts2.interceptor.CreateSessionInterceptor" /> 
<!-- 提供不同的调试用的页面来展现内部的数据状况 -->
<interceptor name="debugging" class="org.apache.struts2.interceptor.debugging.DebuggingInterceptor" /> 
<interceptor name="external-ref" class="com.opensymphony.xwork2.interceptor.ExternalReferencesInterceptor" /> 
<!-- 在后台执行Action,同时将用户带到一个中间的等待页面 -->
<interceptor name="execAndWait" class="org.apache.struts2.interceptor.ExecuteAndWaitInterceptor" /> 
<!-- 将异常定位到一个画面  -->
<interceptor name="exception" class="com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor" /> 
<!-- 提供文件上传功能	-->
<interceptor name="fileUpload" class="org.apache.struts2.interceptor.FileUploadInterceptor" /> 
<!-- 记录用户选择的locale  -->
<interceptor name="i18n" class="com.opensymphony.xwork2.interceptor.I18nInterceptor" /> 
<!-- 输出Action的名字  -->
<interceptor name="logger" class="com.opensymphony.xwork2.interceptor.LoggingInterceptor" />
<!-- 如果一个类实现了ModelDriven,将getModel得到的结果放在Value Stack中 -->
<interceptor name="model-driven" class="com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor" /> 
<!-- 如果一个Action实现了ScopedModelDriven,则这个拦截器会从相应的Scope中取出model调用Action的setModel方法将其放入Action内部 -->
<interceptor name="scoped-model-driven" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor" /> 
<!-- 将请求中的参数设置到Action中去 -->
<interceptor name="params" class="com.opensymphony.xwork2.interceptor.ParametersInterceptor" /> 
<!-- 如果Acton实现了Preparable,则该拦截器调用Action类的prepare方法 -->
<interceptor name="prepare" class="com.opensymphony.xwork2.interceptor.PrepareInterceptor" /> 
<!-- 从struts.xml文件中将<action>中的<param>中的内容设置到对应的Action中 -->
<interceptor name="static-params" class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor" /> 
<!-- 将Action状态存入session和application的简单方法 -->
<interceptor name="scope" class="org.apache.struts2.interceptor.ScopeInterceptor" /> 
<!-- 提供访问HttpServletRequest和HttpServletResponse的方法,以Map的方式访问 -->
<interceptor name="servlet-config" class="org.apache.struts2.interceptor.ServletConfigInterceptor" /> 
<interceptor name="sessionAutowiring" class="org.apache.struts2.spring.interceptor.SessionContextAutowiringInterceptor" /> 
<!-- 输出Action执行的时间 -->
<interceptor name="timer" class="com.opensymphony.xwork2.interceptor.TimerInterceptor" /> 
<!-- 通过Token来避免双击  -->
<interceptor name="token" class="org.apache.struts2.interceptor.TokenInterceptor" /> 
<!-- 和Token Interceptor一样,不过双击的时候把请求的数据存储在Session中 -->
<interceptor name="token-session" class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor" /> 
<!-- 使用action-validation.xml文件中定义的内容校验提交的数据 -->
<interceptor name="validation" class="com.opensymphony.xwork2.validator.ValidationInterceptor" /> 
<!-- 调用Action的validate方法,一旦有错误返回,重新定位到INPUT画面 -->
<interceptor name="workflow" class="com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor" /> 
<!-- 存储或者访问实现ValidationAware接口的Action类出现的消息,错误,字段错误等 -->
<interceptor name="store" class="org.apache.struts2.interceptor.MessageStoreInterceptor" /> 
<!-- 添加了checkbox自动处理代码,将没有选中的checkbox的内容设定为false,而html默认情况下不提交没有选中的checkbox -->
<interceptor name="checkbox" class="org.apache.struts2.interceptor.CheckboxInterceptor" /> 
<!-- 通过参数激活profile -->
<interceptor name="profiling" class="org.apache.struts2.interceptor.ProfilingActivationInterceptor" /> 

 

 二、自定义拦截器

 

1、自定义一个实现com.opensymphony.xwork2.interceptor.Interceptor接口(或者继承com.opensymphony.xwork2.interceptor.AbstractInterceptor)的类

实现Iterceptor接口

public class InterceptorImpl implements Interceptor {

	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	public void init() {
		// TODO Auto-generated method stub
		
	}

	public String intercept(ActionInvocation arg0) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
}

 

继承AbstractInterceptor

public class AbstractExt extends AbstractInterceptor {

	public String intercept(ActionInvocation arg0) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
}

  

2、在struts.xml中注册一个拦截器

<interceptors>
	<interceptor name="拦截器名称" class="类路径" />
	<interceptor-stack name="">
		<interceptor-ref name=""></interceptor-ref>
	</interceptor-stack>
</interceptors>

 

3、在需要使用的Action中引用上述定义的拦截器

 

<action name="login" class="">
	<interceptor-ref name="拦截器名称">
		<param name="参数名">值</param>
	</interceptor-ref>
</action>

 

分享到:
评论

相关推荐

    struts2.0拦截器、crud例子与用法

    struts2.0描述了拦截器并有对应的例子,用struts实现crud 用法及例子,并介绍了struts2的action的流程 及请求过程

    Struts2.0拦截器总结

    主要总结了struts2.0中的拦截器,对于初学者有一定的帮助,里面也有部分代码演示

    struts2.0拦截器完整

    初学者拦截器的简单应用例子 初学者拦截器的简单应用例子

    struts2.0中文教程

    07 Struts 2的基石——拦截器(Interceptor) 08 在Struts 2中实现IoC 09 在Struts 2中实现文件上传 10 在Struts 2中实现CRUD 11 Struts 2中的OGNL 12 trus 2的新表单标志的使用 13 Struts 2与AJAX

    Struts 2.0系列(MAX)

    Struts 2.0系列(MAX),pdf格式,全...Struts 2的基石——拦截器(Interceptor) 在Struts 2中实现IoC 在Struts 2中实现文件上传 在Struts 2中实现CRUD Struts 2中的OGNL Strus 2的新表单标志的使用 Struts 2与AJAX

    Struts2.0中文教程权威版

    07 Struts 2的基石——拦截器(Interceptor) 08 在Struts 2中实现IoC 09 在Struts 2中实现文件上传 10 在Struts 2中实现CRUD 11 Struts 2中的OGNL 12 trus 2的新表单标志的使用 13 Struts 2与AJAX Struts2中用...

    信息系统软件设计:第3章 Struts2.0-拦截器.ppt

    信息系统软件设计:第3章 Struts2.0-拦截器.ppt

    struts2.0非常实用的学习实例 本人自己精心准备

    拦截器 验证器 struts.xml配置文档详解 本人在该实例中遇到的最大问题及解决方案: "struts2.0做文件上传关于所加载的错误包造成的问题心得" 1:commons-io-1.4.jar 做上传时,如果用的该包是1.0的就经常出经上传不...

    struts 2.0 的拦截器

    针对图片的格式、大小不符合进行拦截,对于给与的提示进行格式化。

    个人知识管理系统 Struts2.0 + Spring + Hibernate

    Struts2.0 + Spring + Hibernate + DWR 对于三大框架目前还在学习阶段,做得不好的地方欢迎来mail指正yukiceo@126.com,或http://blog.csdn.net/yukiceo 每天面对大量的知识,时间一长,容易造成某些知识点的生疏...

    struts 2.0 详细讲解 4个PPT

    struts 拦截器 struts 标签 struts配置详解 struts 初级 掌握了这四个pPT你也就会了struts2.0

    基于struts2.0的进销存管理系统

    采用了struts2.0框架,拦截器,国际化,i18n,action自动获取表单的属性值,FileterDispatch等等,struts标签

    struts2.0.jar

    · 引入拦截器: Struts 2为拦截器(interceptor)提供了全面支持。拦截器可在Action类执行前后加以执行。拦截器经配置后,可以把工作流程或者验证等常见功能作用到请求上。所有请求通过一组拦截器传送,之后再发送到...

    达内Struts2.0学习之当当网系统学习案例

    Struts 2.0技术综合应用,包括上传图片功能,明文加密算法SHA-1和MD5,上传用户头像,根据action随机生成验证码,用链接实现数据的分页处理,以及拦截器和Logger日志框架的引入,总之相当强大,学习Struts 2.0,把这...

    最新struts2.0教程

    最近收集到的struts2.0教程.包含有拦截器,上下传,CRUD,tablibs,国际化,struts2与ajax结合等等.........

    struts2.0编程实例

    几个利用Struts2.0的编程实例,本实例很好的说明了,Struts2的核心技术之一--拦截器的原理!

    J2EE(Struts_拦截器)

    J2EE STRUTS2.0用MyEclipse做的拦截器例子

    个人认为目前最完备的Struts2教程

    07 Struts 2的基石——拦截器(Interceptor) 08 在Struts 2中实现IoC 09 在Struts 2中实现文件上传 10 在Struts 2中实现CRUD 11 Struts 2中的OGNL 12 Struts 2的新表单标志的使用 13 Struts 2与AJAX

Global site tag (gtag.js) - Google Analytics