- 浏览: 1260669 次
- 性别:
- 来自: 常州
文章分类
- 全部博客 (499)
- java (101)
- linux (82)
- mysql (30)
- javascript (45)
- Oracle (12)
- ext (14)
- 虚拟机 (1)
- 搜索引擎 (2)
- struts2 (11)
- 设计模式 (9)
- nginx (17)
- tomcat (12)
- 随想 (10)
- spring (18)
- svn (1)
- flash (3)
- UML (1)
- 数据结构 (7)
- 算法 (2)
- 网摘 (9)
- 数据库 (15)
- ibatis (3)
- jquery (31)
- lucene (1)
- hibernate (14)
- Myeclipse (4)
- 线程 (7)
- jbpm (4)
- 重构 (1)
- mantis (3)
- MediaWiki (4)
- ExtMail (1)
- MDaemon (1)
- egit (1)
- dwr (7)
- sitemesh (2)
- mybatis (1)
- ico (1)
- hadoop (5)
- jsoup (1)
- urlrewrite (2)
- jstl (1)
- spring3 (2)
- aop (2)
- 定时器 (1)
- Quartz (2)
- apache (1)
- php (1)
- security (1)
- iptables (2)
- QQ (1)
- mysqldump (1)
- vim (1)
- memcached (4)
- jad (1)
- 微博 (1)
- html5 (1)
- css3 (1)
- httpclient (10)
- google (1)
- shortUrl (1)
- json (2)
- virtualBox (1)
- mantisBT (2)
- htmlunit (1)
- selenium (2)
- mail (1)
- 正则表达式 (4)
- html (3)
- css (2)
- jatoolsPrinter (1)
- 图片处理 (1)
- hql (1)
- webservice (1)
- 分词 (3)
- 短信 (1)
- VPS (1)
- 事务 (1)
- 广告 (1)
- 画廊 (1)
- git (3)
- github (1)
- openshift (1)
- 缓存 (1)
- web (3)
- android (3)
- c3p0 (1)
- 邮箱 (1)
- memcache (2)
- windows (2)
- js (14)
- 编辑器 (1)
- 打印 (1)
- centos (5)
- boneCP (1)
- 连接池 (1)
- sql (1)
- nosql (1)
- MongoDB (1)
- 浏览器 (1)
- node (1)
- node.js (1)
- backbone.js (1)
- lazyload (1)
- Switch Off (1)
- Titanium (1)
- 网站架构 (1)
- WebDriver (1)
- APJP (1)
- 代理 (1)
- comet (1)
- kendoui (1)
- UI (2)
- 互联网 (1)
- localStorage (1)
- 记录 (1)
- 微信 (2)
- Sphinx (1)
- netty (1)
- js,mvvm,Avalon (1)
- 安卓 (1)
- Tengine (1)
- 大数据 (1)
- 手机 (1)
- paypal (1)
- SaaS (1)
- gitlab (1)
- nodejs (1)
- React (1)
- shadowsocks (0)
- vpn (0)
- 验证码 (1)
- SSL (2)
- SEO (1)
- IntelliJ (1)
- 敏捷开发 (1)
- 项目管理 (1)
- 爬虫 (1)
- 正则 (1)
- owncloud (1)
- 云存储 (1)
- ajax (1)
- pjax (1)
- jdk (1)
- zookeeper (1)
- phantomjs (1)
- ELK (1)
- springcloud (1)
- IDEA (1)
- hexo (1)
- ss (1)
- letencrypt (1)
最新评论
-
peakandyuri:
这个是有BUG的,数字小体现不出来,数字大了就不对了,但是Ja ...
java十进制转换N进制并反转换的工具类 -
ginolai:
然后是相关配置:/etc/sysconfig/iptables ...
Linux中iptables设置详细 -
bzhao:
我测试没啥区别啊!
Thread.sleep()和Thread.currentThread().sleep()区别 -
zhl549342097:
match == false
Spring Security 3.1 中功能强大的加密工具 PasswordEncoder -
hellotieye:
renzhengzhi 写道drager 写道用jsoup后解 ...
jsoup select 选择器
一、理解Struts2拦截器
1. Struts2拦截器是在访问某个Action或Action的某个方法,字段之前或之后实施拦截,并且Struts2拦截器是可插拔的,拦截器是AOP的一种实现. 2. 拦截器栈(Interceptor Stack)。Struts2拦截器栈就是将拦截器按一定的顺序联结成一条链。在访问被拦截的方法或字段时,Struts2拦截器链中的拦截器就会按其之前定义的顺序被调用。 二、实现Struts2拦截器原理 Struts2拦截器的实现原理相对简单,当请求struts2的action时,Struts 2会查找配置文件,并根据其配置实例化相对的 拦截器对象,然后串成一个列表,最后一个一个地调用列表中的拦截器 三、定义Struts2拦截器。 Struts2规定用户自定义拦截器必须实现com.opensymphony.xwork2.interceptor.Interceptor接口。该接口声明了3个方法, void init(); 其中,init和destroy方法会在程序开始和结束时各执行一遍,不管使用了该拦截器与否,只要在struts.xml中声明了该Struts2拦截器就会被执行。 不过,struts中又提供了几个抽象类来简化这一步骤。 都是模板方法实现的。 其中AbstractInterceptor提供了init()和destroy()的空实现,使用时只需要覆盖intercept()方法; 而MethodFilterInterceptor则提供了includeMethods和excludeMethods两个属性,用来过滤执行该过滤器的action的方法。可以通过param来加入或者排除需要过滤的方法。 一般来说,拦截器的写法都差不多。看下面的示例: 四、配置Struts2拦截器 Struts2拦截器需要在struts.xml中声明,如下struts.xml配置文件 <package name="default" extends="struts-default"> 拦截器 名字 说明 Alias Interceptor alias 在不同请求之间将请求参数在不同名字件转换,请求内容不变 Chaining Interceptor chain 让前一个Action的属性可以被后一个Action访问,现在和chain类型的result()结合使用。 Checkbox Interceptor checkbox 添加了checkbox自动处理代码,将没有选中的checkbox的内容设定为false,而html默认情况下不提交没有选中的checkbox。 Cookies Interceptor cookies 使用配置的name,value来是指cookies Conversion Error Interceptor conversionError 将错误从ActionContext中添加到Action的属性字段中。 Create Session Interceptor createSession 自动的创建HttpSession,用来为需要使用到HttpSession的拦截器服务。 Debugging Interceptor debugging 提供不同的调试用的页面来展现内部的数据状况。 Execute and Wait Interceptor execAndWait 在后台执行Action,同时将用户带到一个中间的等待页面。 Exception Interceptor exception 将异常定位到一个画面 File Upload Interceptor fileUpload 提供文件上传功能 I18n Interceptor i18n 记录用户选择的locale Logger Interceptor logger 输出Action的名字 Message Store Interceptor store 存储或者访问实现ValidationAware接口的Action类出现的消息,错误,字段错误等。 Model Driven Interceptor model-driven 如果一个类实现了ModelDriven,将getModel得到的结果放在Value Stack中。 Scoped Model Driven scoped-model-driven 如果一个Action实现了ScopedModelDriven,则这个拦截器会从相应的Scope中取出model调用Action的setModel方法将其放入Action内部。 Parameters Interceptor params 将请求中的参数设置到Action中去。 Prepare Interceptor prepare 如果Acton实现了Preparable,则该拦截器调用Action类的prepare方法。 Scope Interceptor scope 将Action状态存入session和application的简单方法。 Servlet Config Interceptor servletConfig 提供访问HttpServletRequest和HttpServletResponse的方法,以Map的方式访问。 Static Parameters Interceptor staticParams 从struts.xml文件中将中的中的内容设置到对应的Action中。 Roles Interceptor roles 确定用户是否具有JAAS指定的Role,否则不予执行。 Timer Interceptor timer 输出Action执行的时间 Token Interceptor token 通过Token来避免双击 Token Session Interceptor tokenSession 和Token Interceptor一样,不过双击的时候把请求的数据存储在Session中 Validation Interceptor validation 使用action-validation.xml文件中定义的内容校验提交的数据。 Workflow Interceptor workflow 调用Action的validate方法,一旦有错误返回,重新定位到INPUT画面 Parameter Filter Interceptor N/A 从参数列表中删除不必要的参数 Profiling Interceptor profiling 通过参数激活profile
void destroy();
String intercept(ActionInvocation invocation) throws Exception;
intercept方法就是拦截的主体了,每次拦截器生效时都会执行其中的逻辑。
public abstract class AbstractInterceptor implements Interceptor;
public abstract class MethodFilterInterceptor extends AbstractInterceptor;
package interceptor;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
public class MyInterceptor implements Interceptor {
public void destroy() {
// TODO Auto-generated method stub
}
public void init() {
// TODO Auto-generated method stub
}
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("Action执行前插入 代码");
//执行目标方法 (调用下一个拦截器, 或执行Action)
final String res = invocation.invoke();
System.out.println("Action执行后插入 代码");
return res;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.objectFactory" value="spring" />
<interceptors>
<interceptor name="MyInterceptor" class="interceptor.MyInterceptor"></interceptor>
<interceptor-stack name="myInterceptorStack">
<interceptor-ref name="MyInterceptor"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<action name="loginAction" class="loginAction">
<result name="fail">/index.jsp </result>
<result name="success">/success.jsp</result>
<interceptor-ref name="myInterceptorStack"></interceptor-ref>
</action>
</package>
</struts>
发表评论
-
2017年Struts漏洞修复:版本从2.3.15.1升级到2.3.32
2017-03-24 15:10 1955如果你当前的项目使用了Struts2.3.5至 Strut ... -
struts2国际化信息
2011-12-06 15:44 11501.资源文件 中文文件messageResour ... -
struts2中action的重定向和转发的设置
2011-12-04 18:39 3023<?xml version="1.0&quo ... -
Myeclipse自动加入struts 2 Core Libraries导致antlr错误
2011-12-02 18:31 1027解决方法: 选择windows---preferences- ... -
struts1与struts2的区别
2011-10-18 21:52 958本文是转载,来源互联 ... -
struts2初学之form上传
2010-04-13 17:41 1474以前struts1使用的FormFile我不是很喜欢,这下好了 ... -
struts2初学之form提交登录验证
2010-04-13 14:35 2534本篇介绍了struts2的最基本的form提交,并且使用了其P ... -
引用一下:struts1和struts2之间的区别
2010-04-13 12:05 1264Struts2与Struts1的对比 ... -
struts2初学之hello,struts2
2010-04-13 11:53 1177本篇应用了最基本的struts跳转程序来解释最基本的strut ... -
开始学习struts2
2010-04-13 10:01 1176说来惭愧,做了几年java技术基本都用的struts1,感觉跟 ...
相关推荐
struts2拦截器应用小例子,与大家共分享
Struts2拦截器的实现原理相对简单,当请求struts2的action时,Struts 2会查找配置文件,并根据其配置实例化相对的 拦截器对象,然后串成一个列表,最后一个一个地调用列表中的拦截器 三、定义Struts2拦截器。 ...
Struts2 中拦截器与过滤器的区别及执行顺序 Struts2 中的拦截器(Interceptor)和过滤器(Filter)是两个不同的概念,虽然它们都可以影响请求的处理过程,但它们的作用域、执行顺序和实现机制都有所不同。 拦截器...
简单的struts2拦截器利用session拦截用户登录.docx
NULL 博文链接:https://605113068.iteye.com/blog/1725133
Struts2拦截器入门实例,高手就不用看了,呵呵
struts2拦截器详解,通过一个简单的例子让大家明白sturts2拦截器使用方法。
一个关于struts拦截器的简单例子,适合初学者!
主要是有关Struts2中拦截器的配置和解析,简单的应用。
简单的拦截器例子,适合初学者学习,也是一个备忘录
一个简单的拦截器,配置说明都很详细, 一个简单的拦截器,配置说明都很详细。
默认登录页面 http://localhost:8080/Struts_ljq ...登录成功页面有add,delete,modify方法,配置有不同拦截,在后台看拦截信息。...有全局拦截器配置和方法拦截,及监听器简单运用, 仅新手学习demo
strut2 配置自定义拦截器 包括struts2.xml 和 action对应的xml 以及拦截器 可能有点简单 但是基本配置都有
该文档详细描述了struts2中拦截器的原理及使用方法,内含实现简单登录模块的拦截器代码。
这个压缩包里有简单的Struts2拦截器的登录应用,里面有实验报告还有项目源代码。这适合初学ssh
简单的struts2自定义拦截器 很适合web初学者
struts2的一个简单的拦截器例子
struts 拦截器实现权限拦截,例子简单易懂,有详细的注释。
没有与数据库交互,这里简单的演示了一下Struts2中拦截器的使用以及相关配置,希望通过这个小例子可以对初学者有所帮助