A framework tries to automate the common tasks and provides a platform for the users to build applications quickly.
Struts 2 is based on the OpenSymphony Web Works Framework
.
Struts 2 framework implements the Model-View-Controller (MVC
) design pattern.
In Struts 2 the model, view and controller are implemented by the action
, result
and FilterDispatcher
respectively.
The controller's job is to map the user request to appropriate action.
In Struts 2 FilterDispatcher does the job of Controller.
Model contains the data and the business logic.
In Struts 2 the model is implemented by the Action component.
View is the presentation component of the MVC Pattern.
In Struts 2 the view is commonly implemented using JSP, Velocity
Template, Freemaker or some other presentation-layer technology.
The controller receives the user request and determine which Struts 2 action to invoke.
The framework creates an instance of this action and associate it with the newly created instance of the ActionInvocation.
In Struts 2 the invocation of action should pass through a series of interceptors as defined in the application's XML file.
The framework calls the ActionInvocations invoke() method to start the execution of the action.
Each time the invoke() method is called, ActionInvocation consults its state and executes whichever interceptor comes next.
ActionInvocation hands control over to the interceptor in the stack by calling the interceptors intercept() method.
The intercept() method of the interceptor inturn calls the invoke()
method of the ActionInvocation till all the interceptors are invoked, in
the end the action itself will be called and the corresponding result
will be returned back to the user.
Some interceptor do work before the action is executed and some do
work after the action is executed. It's not necessary that it should do
something each time it is invoked.
These interceptors are invoke both before and after the action.
First all the interceptors are executed in the order they are defined in the stack.
Then the action is invoked and the result is generated.
Again all the interceptors present in the stack are invoked in the reverse order.
The other important features of Struts 2 are OGNL
and ValueStack
.
Object-Graph Navigation Language (OGNL) is a powerful expression
language that is used to reference and manipulate data on the
ValueStack.
OGNL help in data transfer
and type conversion
.
OGNL expression language provides simplified stytax to reference java objects.
OGNL is used to bind the java-side data properties to the string-based view layer.
In Struts 2 the action resides on the ValueStack which is a part of the ActionContext
. ActionContext is a global storage area that holds all the data associated with the processing of a request.
When a request comes the params
interceptor helps in moving the request data to the ValueStack.
Now the OGNL does the job of converting the string based form data to
their corresponding java types. OGNL does this by using the set of
available built-in type converters
.
Again when the results are generated the OGNL converts the java types
of the property on the ValueStack to the string-based HTML output.
ActionContext is thread local which means that the values stored in
the ActionContext are unique per thread, this makes the Struts 2 actions
thread safe
.
原文作者:Meyyappan Muthuraman
.
分享到:
相关推荐
### Struts Framework 的工作原理与核心组件解析 #### 一、概述 Struts框架作为Java Web开发中的一个重要组成部分,自2000年初发布以来,便因其强大的功能和易用性而受到广泛欢迎。该框架主要针对MVC(Model-View-...
开发者通过文档分析可以深入了解Struts2的控制流程、JDBC的数据操作以及协同办公系统的常见设计模式和功能实现。通过这个项目,初学者可以学习到Web开发的基本技能,而有经验的开发者则可以从中获取灵感,改进或扩展...
本文主要从概念上讲解什么是struts framework,它的框架结构,组件结构,以及配置讲解。...三、 Struts的工作原理和组件(Struts Componennts) 四、 Struts配置文件简介(Struts Deployment Description)
Struts2是一个基于MVC(Model-View-Controller)设计模式的Java EE应用程序框架,它在Web开发...不过需要注意的是,Struts2自2.5版本后已不再更新,现在推荐使用更现代的框架如Spring MVC或Play Framework进行开发。
- 分析Spring与Struts2如何协同工作,以及它们之间的交互机制。 #### 详细步骤 ##### 1. 在 WEB 应用中加入 Struts2 - **参照示例应用**:根据`struts-2.3.15.3-all\struts-2.3.15.3\apps\struts2-blank.war`...
### Struts 2 整合 Spring 的关键技术点 #### 一、Struts 2 和 Spring 简介 - **Struts 2**:作为Java Web应用开发中的一个重要框架,Struts 2 提供了一种灵活的方式来构建MVC(Model-View-Controller)架构的应用...
通过结合这两个源码包,开发者可以更好地理解Struts 2的工作原理,调试问题,以及定制自己的功能模块。 总的来说,分析Struts 2.3.1.2源码对于深入理解MVC框架、Java Web开发和企业级应用设计具有重要意义。这不仅...
2. **实际案例分析**:通过具体的应用实例,深入理解Struts框架的工作原理及其在实际项目中的应用。 3. **数据库集成**:介绍如何将Struts框架与数据库技术相结合,实现高效的数据访问。 4. **Struts扩展技巧**:...
Struts2、Spring和Hibernate是Java Web开发...通过分析和运行这个项目,开发者可以深入理解这三个框架的协同工作原理,提高Java Web开发技能。同时,它也提醒我们,在实际项目中,正确管理和维护依赖关系是至关重要的。
根据给定的日文Struts学习PPT的内容,我们可以总结出以下关键知识点: ### Struts简介 **Struts** 是一种广泛应用于Java Web应用程序开发的框架。...对于初学者来说,理解Struts的基本架构和工作原理是入门的关键。
- `org-netbeans-modules-framework-xwork.nbm`:XWork是Struts2的基础框架,这个模块可能包含了对XWork的支持。 这些.nbm文件是NetBeans模块化系统的一部分,它们包含了插件的源代码、资源文件和元数据,使得...
源码分析是深入理解Struts2工作原理的关键。在"struts2.0源代码"中,你可以看到框架的核心组件、拦截器、配置解析、动作执行等核心功能的实现。以下是一些主要的知识点: 1. **ActionInvocation**:这是Struts2的...
4. org-netbeans-modules-framework-xwork.nbm:XWork是Struts2的底层工作框架,负责处理Action的执行、拦截器链等功能。这个模块可能包含了对XWork框架的支持,使得开发者可以更好地理解和利用XWork的特性,例如...
现在,我们逐一分析这些jar包的作用和它们在Struts2框架中的角色: 1. `struts2-core-2.0.11.1.jar`:这是Struts2的核心库,包含了框架的主要组件,如Action、Result、Interceptor等。它提供了一整套机制来处理HTTP...
首先,Struts2的源码分析是学习其工作原理的重要途径。通过深入源码,开发者可以理解框架如何处理请求、动作映射、拦截器链等核心功能。源码学习可以帮助我们定制框架,解决特定问题,或者创建自定义插件,提升项目...
### Struts2 + Spring2 + Hibernate3 整合实例源码分析 #### 一、概述 随着企业级应用的发展,为了提高开发效率和系统维护性,越来越多的项目开始采用MVC设计模式。其中,Struts2作为MVC框架中的佼佼者,在前端...
这有助于理解Convention插件如何工作,并能帮助开发者快速构建Struts2应用,减少手动配置的工作量。 总之,Struts2的Convention插件是一种强大的工具,它简化了开发流程,让开发者更加专注于业务逻辑而不是配置细节...