Struts2框架拦截器:

Struts 2框架提供了良好的预配置,并准备使用的盒拦截。下面列出了几个重要的拦截器:

SN Interceptor & 描述
1 alias
Allows parameters to have different name aliases across requests.
2 checkbox
Assists in managing check boxes by adding a parameter value of false for check boxes that are not checked.
3 conversionError
Places error information from converting strings to parameter types into the action‘s field errors.
4 createSession
Automatically creates an HTTP session if one does not already exist.
5 debugging
Provides several different debugging screens to the developer.
6 execAndWait
Sends the user to an intermediary waiting page while the action executes in the background.
7 exception
Maps exceptions that are thrown from an action to a result, allowing automatic exception handling via redirection.
8 fileUpload
Facilitates easy file uploading.
9 i18n
Keeps track of the selected locale during a user‘s session.
10 logger
Provides simple logging by outputting the name of the action being executed.
11 params
Sets the request parameters on the action.
12 prepare
This is typically used to do pre-processing work, such as setup database connections.
13 profile
Allows simple profiling information to be logged for actions.
14 scope
Stores and retrieves the action‘s state in the session or application scope.
15 ServletConfig
Provides the action with access to various servlet-based information.
16 timer
Provides simple profiling information in the form of how long the action takes to execute.
17 token
Checks the action for a valid token to prevent duplicate formsubmission.
18 validation
Provides validation support for actions

完整的细节上面提到的拦截,请loook到Struts2文档。但我会告诉你如何使用拦截器,一般在你的Struts应用程序。

原文地址:https://www.cnblogs.com/borter/p/9502144.html

时间: 2024-08-30 16:20:47

Struts2框架拦截器:的相关文章

【跟我一步一步学Struts2】——拦截器

前言 前面提到过拦截器.而且说拦截器仅仅能拦截Action.这里拦截器的调用体现了责任链模式.为什么说体现了责任链模式呢? 以下的一段话说的非常明确: Struts2将整个运行划分成若干同样类型的元素,每一个元素具备不同的逻辑责任,并将它们纳入到一个链式的数据结构中.而每一个元素又有责任负责链式结构中下一个元素的运行调用. 从代码重构的角度来看,实际上是将一个复杂的系统,分而治之.从而使得每一个部分的逻辑可以高度重用并具备高度可扩展性. 拦截器的原理 Struts2框架的拦截器是动态配置的,假设

Struts2中拦截器的简单实现

Struts2的拦截器和Servlet过滤器类似.在执行Action的execute方法之前,Struts2会首先执行struts.xml中引用 的拦截器,在执行完所有引用的拦截器的intercept方法后,会执行Action的execute方法.在Struts2的拦截器体系中, Struts2的内建拦截器完成了该框架的大部分操作,所以实际的开发过程中通常都是使用系统的拦截器而已.当然我们也可以开发自己的拦截器,类似于过滤器的开发. 原理: Struts2拦截器的实现原理相对简单,当请求Stru

struts2 在拦截器进行注入(根据Action是否实现自定义接口)

例如:常常在Action中都需要获取当前登录的User,就需要获取Session,然后从Session获取当前登录的User,因为这些步骤都是重复操作,可以想办法在拦截器中进行实现,可以自定义一个接口,只要你的Action实现了这个接口,就在自定义拦截器中进行注入.即从拦截器中获取Session,然后设置进行注入. 简单的例子: 一个自定义接口,只要Action实现这个接口,就在拦截器中进行注入 package com.atguigu.surveypark.struts2; import com

【struts2】拦截器基础

1)拦截器是什么? 拦截器(Interceptor)是Struts2最强大的特性之一,它是一种可以让你在Action执行之前和Result执行之后进行一些功能处理的机制.来回顾一下官方给出的Struts2系统架构图中关于拦截器的部分,如下图所示: 这个图清晰的描述出了拦截器的运行地位,就是用来负责在Action执行之前和Result执行之后处理一些功能的类.也就是说,上图示意了有3个拦截器的类,分别是Interceptor1.Interceptor2和Interceptor3,它们分别执行不同的

Struts2自定义拦截器Interceptor以及拦截器登录实例

1.在Struts2自定义拦截器有三种方式: -->实现Interceptor接口 public class QLInterceptorAction implements Interceptor{ private static final long serialVersionUID = 1L; public void destroy() { } public void init() {} public String intercept(ActionInvocation arg0) throws

Struts2 自定义拦截器时Action无法接收到参数

问题:自定义拦截器,没有添加defaultStack导致Action无法接受到参数 解决办法: 方法一,添加defaultStack,然后在Action中引用 自定义的stack,其实defaultStack中也有细分如basicStack等 <interceptors> <interceptor name="checkUser" class="com.common.interceptor.UserInfoInterceptor"></

Spring的AOP,Struts2的拦截器(Interceptor),以及springMVC的(interceptor)

参考外链:http://www.ibm.com/developerworks/cn/java/j-lo-springaopfilter/ 1.首先,spring的AOP作用范围很广,可以使用Aspectj的execution表达式自定以切面的位置. 比如下面的配置service方法执行日志: 1 <!-- 系统日志 --> 2 <bean id="logUtils" class="com.tabchanj.crm.utils.SystemLogUtils&q

【struts2】拦截器的工作模拟实现

Main.java /** * 书本:[struts2] * 功能:模拟拦截器的工作,实际就是递归的思想 * 文件:Main.java * 时间:2014年11月9日20:04:55 * 作者:cutter_point */ public class Main { public static void main(String [] args) { new ActionInvocation().invoke(); } } ActionInvocation.java /** * 书本:[struts

谈谈 Struts2 的拦截器

套话 相信很多人都用过 Struts2 了,当然,对 Struts2 的原理也都比较了解.之前在一个项目中就已经用到了,当初的理解也仅仅是局限在应用的层面上,对于更深层次的原理.机制,了解的并不是很多.现在回过头来,再看 Struts2 的拦截器,相比之前的理解,又别有另一番滋味. 理解 Struts2 的拦截器,英文名为 Interceptor ,至于为什么中文要翻译为拦截器,我想这一定是有原因的,肯定不是一拍脑门,就叫拦截器了(它必定有什么含义在里边).从字面的意思,就是在发送请求的时候,有