重读《Struts In Action》
2015-04-13 08:37
357 查看
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. |
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. |
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 Struts 2 framework comes with built-in support for converting between the HTTP native strings and the following list of Java types:
String— Sometimes a string is just a string. boolean/Boolean— true and false strings can be converted to both primitive and object versions of Boolean. char/Character— Primitive or object. int/Integer, float/Float, long/Long, double/Double— Primitives or objects. Date— String version will be in SHORT format of current Locale (for example, 12/10/97). array— Each string element must be convertible to the array’s type. List— Populated with Strings by default. Map— Populated with Strings by default. |
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. |
相关文章推荐
- Action.perform in struts1.0 & Action.execute in struts1.1
- Java in Action - Struts分页显示
- 如何成功调试《Struts in Action》的第一例
- 黑马程序员 struts问题-------->No configuration found for the specified action: 'type2' in namespace: ''.
- 《Struts in Action》第12章翻译,初稿,第一节
- 《Java in Action》-1 第11章CompletableFuture:组合式异步编程(需重读)
- How to remove the action suffix extension in Struts 2
- Struts in Action: Building Web Applications with the Leading Java Framework
- 研究Struts体系结构(<struts in action>读书笔记)
- 《Struts in Action》阅读心得
- How to remove the action suffix extension in Struts 2
- struts.enable.SlashesInActionNames 无效
- 一、struts使用小贴士(mainly from《struts in action》)
- struts2.0 action result类型
- 关于struts和Spring 结合到一起之后存在ACtion创建单实例还是多
- 3.Struts类型转化器:Action
- 3.Struts访问受保护的页面,动态ActionForward:Action
- 从struts-default包透析redirectAction与chain用法
- ActionContextCleanUp StrutsPrepareAndExecuteFilter StrutsPrepareFilter,StrutsExecuteFilter FilterDispatcher
- struts中action的线程安全问题