`

Struts 2 Framework 工作原理的剖析

 
阅读更多

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 .

 

分享到:
评论

相关推荐

    Struts2教程,很适用哦

    本文主要从概念上讲解什么是struts framework,它的框架结构,组件结构,以及配置讲解。...三、 Struts的工作原理和组件(Struts Componennts) 四、 Struts配置文件简介(Struts Deployment Description)

    Struts原理、开发及项目实施

    Struts原理、开发及项目实施 Holen 2002-9-12 <br/>1、 摘要 2、 关键词 3、 Framework 4、 Struts的起源 5、 Struts工作原理 6、 Struts安装 7、 一个实例 8、 Struts优缺点...

    使用Gradle 构建Struts2、Springframework和hibernate 框架的Java EE 项目模板.zip

    软件开发设计:应用软件开发、系统...云计算与大数据:包括云计算平台、大数据分析、人工智能、机器学习等,云计算是一种基于互联网的计算方式,通过这种方式,共享的软硬件资源和信息可以按需提供给计算机和其他设备。

    论文研究-基于Struts/Spring/Hibernate架构的日志统计分析系统的分析与设计 .pdf

    基于Struts/Spring/Hibernate架构的日志统计分析系统的分析与设计,唐红喜,宋茂强,本文重点介绍了日志统计分析系统的总体设计和技术实现,本系统基于B/S结构.使用MVC模式开发,综合应用了Struts Framework、...

    structs程序设计从入门到精通word文档

    1.1 JSP Framework - Struts介绍 8 1.2 Struts的体系结构 8 1.3 Struts1.0学习文档 8 1.3 JSP流行模板Struts的安装配置 8 1.4Struts 用户指南 8 1.5 你的第一个struts应用程序 8 第2章深入Struts结构 8 2.1人介绍...

    计算机科学系毕业设计论文范文

    详细介绍了在基于Struts2框架下各个模块的实现过程,且以开发过程为基础实现系统所具有的可重用性、可维护性和可扩展性等优势进行了分析。 关键词 MyEclipse开发工具,电子商城,网站安全 ...

    基于Java的驾校在线考试系统设计与实现.docx

    This system selects B/S mode, uses JSP technology to design the system foreground, chooses Struts2 framework and hibernate framework to build the system framework, uses SQL Server 2008 database to ...

    java当当网源码-open-source-learning:技术源码研究

    Struts2源码剖析与架构指导 Struts2技术内幕 ##spring框架源码分析 Spring源码解读与设计详析 Spring技术内幕 ##jquery源码分析 jQuery技术内幕:深入解析jQuery架构设计与实现原理 妙味课堂 jQuery 源码分析视频 ...

    外文翻译 stus MVC

    This definition implies that Struts is a framework, rather than a library, but Struts also contains an extensive tag library and utility classes that work independently of the framework. Figure 5 ...

    Web安全深度剖析(张柄帅)

    8.3.1 Struts2代码执行漏洞 166 8.3.2 ThinkPHP命令执行漏洞 169 8.3 防范命令执行漏洞 169 第9章 文件包含漏洞 171 9.1 包含漏洞原理解析 171 9.1.1 PHP包含 171 9.1.2 JSP包含 180 9.2 安全编写包含 184 9.3 小结 ...

    Java语言基础下载

    Struts framework的工作原理和组件 642 Struts ActionServlet控制器对象 642 Struts Action Classes 642 搞定Action对象 643 处理异常 643 Action的分类 643 Struts Action Mapping 646 使用ActionForward导航 647 ...

    jive.chm

    混淆 1 Sun公司的混淆器JADE 2 RetroGuard的使用方法 <br> JVM 1 JVM之class文件结构 2 JVM 內的資料處理 <br> MVC Framework 1 应用Struts的网站建设 <br> ...

    java实用系统开发指南-2

    本书是国人原创的第一本涉及框架、组件构件等重用概念的Java畅销书,该书通过8个系统,指出了一个成熟Java/J2EE系统设计开发的正确之道:Model(建模)、Patterns(模式)和Framework(框架)。 需求UML分析与域...

    论文研究-一种基于J2EE的软件架构的研究与应用.pdf

    提出了一个基于Struts的软件系统框架WEF(Wrapping EJB Framework),该框架采用隐式实现服务定位,提高了JNDI服务的检索速度;强制使用Object Value降低网络传输的代价;采用配置文件等技术改善EJB的执行灵活性。对...

    java实用系统开发指南-3

    本书是国人原创的第一本涉及框架、组件构件等重用概念的Java畅销书,该书通过8个系统,指出了一个成熟Java/J2EE系统设计开发的正确之道:Model(建模)、Patterns(模式)和Framework(框架)。 需求UML分析与域...

    java实用系统开发指南-1

    需求UML分析与域模型(Domain Model)建立; J2EE架构技术考量和选择,不同的应用有不同的工具; 代码详细设计和模式的应用; 可重用框架Framework的提炼和应用;  Java/J2EE带来的不仅是语言变革;还有工程方法...

    ARCH4系统开发指南

    2.28.2 Struts2校验框架应用 71 2.28.2.1 校验配置文件 71 2.28.2.2 角色Insert页面示例 71 2.28.2.3 用户Query页面示例 73 2.28.2.4 多行输入域校验 75 2.29 多语言管理 77 2.29.1 定义输入域的name属性和资源文件 ...

    “桂林高新杯”软件设计大赛.doc

    " " "2、JSP、JavaBean、Servlet、JDBC、Struts、Hibernate、Spring" " "、EJB、 Web Service、JMS、JTA、JTS技术开发; " " "3、系统集成、优化。 " "数据库应用 "考核要点 "分值 "20 " "数据库应用 "1、数据库...

    学生成绩管理系统-课程设计

    The development tools is MyEclipse, database is MySQL, integrated framework is struts and hibernate. Key words: J2EE; Grade Management; MySql; MyEclipse 目 录 Abstract II 1 绪论 1 1.1高校学生...

    iuhyiuhkjh908u0980

    2.更新至最新的 web framework API。3.重新设计了配置面板,支持更加灵活的最初配置。4.少量针对的 ... by gml520 2009-08-27 回复 (4) 新版本的PrettyTools发布,支持 ... PrettyFaces: EL API访问PrettyContext ...

Global site tag (gtag.js) - Google Analytics