重读《Struts In Action》
|
Figure 1.1. The Java Servlet API exposes the HTTP client/server protocol to the Java platform. Struts 2 is built on top of that.
|
For web applications, HTTP has two hurdles to get over. It’s stateless, and it’s text based.
Don’t reinvent the wheel
FilterDispatcher: early version
Figure 1.4. Struts 2 request processing uses interceptors that fire before and after the action and result.

the ValueStack is a storage area that holds all of the data associated with the processing of a request.
The ActionContext contains all of the data that makes up the context in which an action occurs. This includes the ValueStack but also includes stuff the framework itself will use internally, such as the request, session, and application maps from the Servlet API.
OGNL is a powerful expression language (and more) that is used to reference and manipulate properties on the ValueStack.
Typically, it is considered bad form to obtain the contents of the ActionContext yourself. The framework provides many elegant ways to interact with that data without actually touching the ActionContext, or the ValueStack, yourself. Primarily, you’ll use OGNL to do this.
Figure 2.6. Anatomy of a URL: mapping a URL namespace to a Struts 2 action namespace

Actions do three things. First, as you probably understand by now, an action’s most important role, from the perspective of the framework’s architecture, is encapsulating the actual work to be done for a given request. The second major role is to serve as a data carrier in the framework’s automatic transfer of data from the request to the view. Finally, the action must assist the framework in determining which result should render the view that’ll be returned in the request response.
This important params interceptor has been the one moving data from the request parameters to our action’s JavaBeans properties.
the DefaultWorkflowInterceptor, to provide basic validation.
FileUploadInterceptor.
|
Figure 4.1. ActionInvocation encapsulates the execution of an action with its associated interceptors and results.
|
We need to point out one important detail before moving on. Interceptor instances are shared among actions. Though a new instance of an action is created for each request, interceptors are reused. This has one important implication. Interceptors are stateless. Don’t try to store data related to the request being processed on the interceptor object. This isn’t the role of the interceptor. An interceptor should just apply its processing logic to the data of the request, which is already conveniently stored in the various objects you can access through the ActionInvocation.
OGNL is a powerful technology that’s been integrated into the Struts 2 framework to help with data transfer and type conversion. OGNL is the glue between the framework’s string-based HTTP input and output and the Java-based internal processing.
|
Figure 5.1. OGNL provides the framework’s mechanism for transferring and type-converting data.
|
The ValueStack is a Struts 2 construct that presents an aggregation of the properties of a stack of objects as properties of a single virtual object. If duplicate properties exist—two objects in the stack both have a name property—then the property of the highest object in the stack will be the one exposed on the virtual object represented by the ValueStack. The ValueStack represents the data model exposed to the current request and is the default object against which all OGNL expressions are resolved.
The Struts 2 framework comes with built-in support for converting between the HTTP native strings and the following list of Java types:
|
When specifying the type for Lists and other Collections, take care not to preinitialize your List.
The ActionContext contains all of the data available to the framework’s processing of the request, including things ranging from application data to session- or application-scoped maps. All of your application-specific data, such as properties exposed on your action, will be held in the ValueStack, one of the objects in the ActionContext.
All OGNL expressions must resolve against one of the objects contained in the ActionContext. By default, the ValueStack will be the one chosen for OGNL resolution, but you can specifically name one of the others, such as the session map, if you like.
|
Figure 6.1. The ActionContext holds all the important data objects pertaining to a given action invocation; OGNL can target any of them.
|
拦截器在启动服务器的时候,就已经初始化好了。
重读《Struts In Action》的更多相关文章
- 关于Spring的Controller及Struts的Action的多线程的注意
struts是线程安全,并不是指多线程,而是指单态,当多个用户访问一个请求的时候,服务器内存中只有一个与之对应的action类对象,execute方法加上了同步关键字,如果你在action里加上一个全 ...
- struts中action名称反复导致的神秘事件
近期由于项目需求变更.须要本人对当中的某个业务功能进行改动.本人依照前台页面找action,依据action找代码的逻辑进行了改动(公司项目是ssh框架,struts配置全部是通过注解的方式进行.配置 ...
- 实现Spring管理struts的Action
struts2和spring的整合,关键点在于struts2中的action要纳入spring容器的管理中成为一个bean. 可以在struts2中配置: <struts> ...
- (五)Struts之Action类基础(二)
上一章节末((三)Struts之Action类基础(一))介绍了如何获取用户输入数据的获取.接着就是在Struts中怎么把数据响应给用户端,这就必须要求我们把数据放到作用域中,然后才能显示到用户浏览器 ...
- JavaWeb_(Struts2框架)Struts创建Action的三种方式
此系列博文基于同一个项目已上传至github 传送门 JavaWeb_(Struts2框架)Struts创建Action的三种方式 传送门 JavaWeb_(Struts2框架)struts.xml核 ...
- Struts中Action三种接收参数的方式?
前言: 前面已经有一篇随笔介绍了Struts2的大概原理.本文就Struts2中Action与jsp页面进行数据对接时介绍几种常见方法! 值栈ValueStack 3个Action Action1 p ...
- struts+service+action+数据库
用户登录流程 1.jsp根据form表单中的action的login <form action="/test02/login" method="post&quo ...
- 初次了解struts的action类
Action类真正实现应用程序的事务逻辑,它们负责处理请求.在收到请求后,ActionServlet会为这个请求选择适当的Action 如果需要,创建Action的一个实例 调用Action的perf ...
- struts 在Action中访问web元素(request,session等)
出发jsp: <?xml version="1.0" encoding="GB18030" ?> <%@ page language=&quo ...
随机推荐
- void指针(void*)用法
首先看一段测试代码: #include <stdio.h> int void_test(void* data) { ; num = *(int*)data; printf("nu ...
- CSS控制div宽度最大宽度/高度和最小宽度/高度
在网页制作中经常要控制div宽度最大宽度/高度或者最小宽度/高度,但是在IE6中很多朋友都会遇到不兼容的头疼问题,包括我也经常遇到这样的问题,在百度查了很多都没法解决,后来在一个论坛上学习到,在这里跟 ...
- UISearchBar去除背景颜色
UISearchBar *searchBar=[[UISearchBar alloc]initWithFrame:frame]; //这个设置背景透明可能无效 searchBar.background ...
- ASP.NET的学习之asp.net整体运行机制
1.浏览器向服务器发送请求报文,服务器端的软件比如是IIS,接受请求 2.IIS通过aspnet_isapi.dll 这个程序集来请求FrameWork中的ASP.Net框架,这是对于集成模式 3.进 ...
- unison+inotify实现文件双向自动同步
nfs适合存小图片和小文件,有一个致命的缺点,就是其中一台web服务挂掉之后,会直接导致web页面无法访问,动态的那种数据, 而且数据量很大的数据不适合nfs Unison是一款跨平台(window, ...
- PHP系统函数
(一)字符串处理函数 Chr函数 作用:根据ASCII码返回相应的字符. 语法:string chr(int ascii): Chop函数 作用:去除字符串中连续空格和空白行. 语法:string c ...
- Android消息推送完美方案[转]
转自 Android消息推送完美方案 推送功能在手机应用开发中越来越重要,已经成为手机开发的必须.在Android应用开发中,由于众所周知的原因,Android消息推送我们不得不大费周折.本文就是用来 ...
- jQuery操作 input type=checkbox的实现代码
代码如下: <input type="checkbox">: 2012欧洲杯"死亡之组"小组出线的国家队是:<br> <input ...
- Laravel 5 基础(十二)- 认证
Laravel 出厂已经带有了用户认证系统,我们来看一下 routes.php,如果删除了,添加上: Route::controllers([ 'auth' => 'Auth\AuthContr ...
- Java命名:
如果没有public类,就和遵循文件名命名规则: 1.一个.java文件只能有1个public class(暗示可以没有) 2.如果有public class,那么文件名必须与修饰符为public的类 ...



