`
shiwj1010
  • 浏览: 97326 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Struts 2.0拦截器

    博客分类:
  • j2ee
阅读更多
在Struts 2.0 中的拦截器,要实现com.opensymphony.xwork2.interceptor.Interceptor接口,在struts.xml中配置。可以用拦截器来完成调用Action业务逻辑之前的预处理或是之后的善后处理。还可以通过配置多个拦截器来满足action需求。

Interceptor stack是由多个拦截器组成的拦截器组,在拦截器组中可以对每一个拦截器映射。所有进行配置拦截器时,不必对每一个拦截器进行配置,而只需对interceptor stack进行配置即可。在struts 2中默认配置了一个全局interceptor stack,包括Exception Interceptor、Validation Interceptor等。

在这个实例当中,我将配置一个时间拦截器,用来统计每个action的请求时间。
package interceptor;

import com.opensymphony.xwork2.ActionInvocation;      
import com.opensymphony.xwork2.interceptor.Interceptor;

public class ActionTimer implements Interceptor{      
    public String intercept(ActionInvocation next) throws Exception {      
        long t1 = System.currentTimeMillis();      
        String s= next.invoke();      
        long t2 = System.currentTimeMillis();      
        System.out.println("Action "+next.getAction().getClass().getName()+" took "+(t2-t1)+" millisecs");      
        return s;      
    }      
          
    public void init() {      
    }      
    public void destroy() {      
    }      
}  


struts.xml
 
<?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>     
    <package name="interceptor" extends="struts-default">     
        <interceptors>     
            <interceptor name="actiontimer"     
                class="interceptor.ActionTimer" />     
     
            <interceptor-stack name="demostack">     
                <interceptor-ref name="defaultStack" />     
                <interceptor-ref name="actiontimer" />     
            </interceptor-stack>     
        </interceptors>     
        <default-interceptor-ref name="demostack" />     
        <action name="InterceptorDemo"     
            class="interceptor.action.InterceptorDemo">     
            <result>http://www.bt285.cn /interceptor/interceptordemo.jsp</result>     
        </action>     
    </package>     
     
</struts>   
分享到:
评论

相关推荐

    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