Struts 2 FrameWork Tutorial
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.
- 大小: 22.8 KB
- 大小: 7.9 KB
分享到:
相关推荐
《Struts 2 设计与编程教程》是Budi Kurniawan撰写的一本深入探讨Struts 2框架的专业书籍,由Brainy Software出版社于2008年1月25日出版。该书共有576页,旨在提供理论解释和实际应用,帮助读者掌握如何在Struts开发...
通过《Java Struts Tutorial》这份教程,你可以全面了解Struts框架的各个方面,从基本概念到实战应用,一步步提升你的Java Web开发技能。在实际工作中,Struts可以帮助你构建高效、模块化的应用,同时,学习Struts也...
Spring MVC 就是类似于 Struts2 的 MVC 框架,属于 SpringFrameWork 的后续产品。 2 为什么学 Spring MVC? SpringMVC 与 Struts2 区别 对比项目 SrpingMVC Struts2 优势 国内市场情况 有大量用户,一般新项目启动...
6. **Web Frameworks**:Java世界中有许多优秀的Web框架,如Struts、Play Framework和Vaadin,它们简化了开发流程,提供了强大的功能,如表单验证、国际化、数据绑定等。 在"webui-tutorial-master"这个项目中,你...
4. **Web开发**:《Java Servlet编程》、《Java EE编程技术》、《构建J2EE应用程序》、《Spring基础教程》、《Struts 2 in Action》、《Spring Framework 开发参考手册》以及《轻量级 J2EE 企业应用实战》等书籍,...
2. **Part 2: Create Hello World Application in Spring 3.0 MVC** - 通过创建一个简单的Hello World应用,读者将学会如何配置Spring MVC环境并处理第一个HTTP请求。 3. **Part 3: Handling Forms in Spring 3.0 ...
Tiles(也称为Tiles 2)是Apache Struts的一个子项目,提供视图组合功能,用于构建复杂的Web页面布局。它允许将页面分解为可重用的部分(tiles),并通过定义模板来组合这些部分。Tiles与Maven结合使用,可以帮助...
- **Servlets** 和 **JSPs**:经典的 Model 2 架构,实现了业务逻辑和表示层的基本分离,但依然缺乏足够的灵活性和可扩展性。 ##### 2.2 现有的框架挑战 - **用户界面与模型无法完全分离**:尽管引入了 Expression...
The framework automatically handles the implementation details, such as layout managers and Swing components. #### Chapter Summaries - **Chapter 1: Introduction to JavaFX** - This chapter ...