博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Struts 2 FrameWork Tutorial
阅读量:2427 次
发布时间:2019-05-10

本文共 3369 字,大约阅读时间需要 11 分钟。

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.

转载地址:http://spjmb.baihongyu.com/

你可能感兴趣的文章
“你写的 Bug 让我来改好吗” | 每日趣闻
查看>>
大厂技术文档:Redis+Nginx+Spring全家桶+Dubbo精选
查看>>
笑死,别再黑程序员了好吗? | 每日趣闻
查看>>
Python 爬取 13966 条运维招聘信息,这些岗位最吃香
查看>>
28 岁退休程序员自述:不是富二代,行政专业出身,非典型程序员
查看>>
那时刚毕业的我,曾参与惊心动魄 3Q 大战
查看>>
程序员爬取 5000+ 口红商品数据,差点比女朋友更懂口红?
查看>>
30 张图解 | 高频面试知识点总结:面试官问我高并发服务模型哪家强?
查看>>
以太坊创始人V 神:普通人看见现在,天才看见未来
查看>>
厉害!从电影花瓶到 Wi-Fi 之母,这才是乘风破浪的姐姐!
查看>>
中国开源大爆发进行时,你没掉队吧?
查看>>
用 Python 实现抖音上的“人像动漫化”特效,原来这么简单!
查看>>
一周内咸鱼疯转 2.4W 次,最终被所有大厂封杀!
查看>>
关于鸿蒙 2.0,那些开发者不知道的一切
查看>>
Google 排名第一的语言,引数十万人关注:搞定它,技术大牛都甘拜下风
查看>>
JavaScript 爆红后,微软为何还要开发 TypeScript?
查看>>
软件开发行业,年轻与大龄程序员的生存现状
查看>>
王者荣耀活动精选 Blink 第二弹来袭!
查看>>
打开数“智”化之门,一字之差带来的思考
查看>>
阿里技术人的成长路径是什么?
查看>>