struts2 in action学习笔记

[b]Struts2 Action职责[/b]
[list]
[*]1.处理实际的业务逻辑,这一点与Struts1.x Action作用相同
[*]2.数据转换,自动处理从request里面提取的请求参数。实际上依赖interceptor实现
[*]3.请求转发,跳转到试图
[/list]
[b]Struts 2 packages[/b]
it’ll organize your actions and other components into logical containers called packages
Struts2 package 和java包相似,都是按照功能或者业务领域把类分组。同时Struts2 package提供了继承机制。
<package name="chapterThreeSecure" namespace="/chapterThree/secure"
extends="struts-default">
<action name="AdminPortfolio" >
<result>/chapterThree/AdminPortfolio.jsp</result>
</action>
<action name="AddImage" >
<result>/chapterThree/ImageAdded.jsp</result>
</action>
<action name="RemoveImage" >
<result>/chapterThree/ImageRemoved.jsp</result>
</action>
</package>


[b]ValueStack[/b]
The Value-Stack holds a stack of objects. These objects all have properties. The magic of the ValueStack is that all the properties of these objects appear as properties of the ValueStack itself.
Struts Action被放在ValueStack中,所以所有Action的实例变量都是ValueStack的properties。ValueStack中的所有properties都被暴露给当前request.

[b]ActionContext[/b]
ActionContext中包含session,request,application以及ValueStack中的数据。ActionContext相当于一个大的map。我们可以在页面中通过struts标签通过OGNL表达式访问ActionContext中的对象。

[b]OGNL[/b]
OGNL expression必须选择一个Root Object作为访问起点,在Struts2中,ValueStack就是这个Root Object。

[b]再论ValueStack[/b]
当Struts2接受一个请求时,它迅速创建ActionContext,ValueStack,action object。然后action被存到ValueStack,所以action的实例变量可以被OGNL访问。

[b]Interceptors[/b]
ActionInvocation包装了Action执行的详细信息。ActionInvocation持有Action所有的拦截器引用。
public String intercept(ActionInvocation invocation) throws Exception {
long startTime = System.currentTimeMillis();
String result = invocation.invoke();
long executionTime = System.currentTimeMillis() - startTime;
... log the time ...
return result;
}

<package name="chapterFourSecure" namespace="/chapterFour/secure"
extends="struts-default">
<interceptors>
<interceptor name="authenticationInterceptor"
class="manning.utils.AuthenticationInterceptor"/>
<interceptor-stack name="secureStack">
<interceptor-ref name="authenticationInterceptor"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="secureStack"/>
. . .
</package>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值