Action请求流程分析

Strut2流程分析-----从请求到Action方法()
首先请求会调用strutsPrepareAndExcuteFliter----(这个就是我们在web.xml文件中所配置的那个拦截器吧,所有Action请求都要过这个拦截器)的doFilter()方法
然后会调用StrutsActionProxy类的excute()方法,生成一个代理类(ActionProxy)
ActionProxy 是 Action 的一个代理类,也就是说Action的调用是通过 ActionProxy 实现的,就是我们定义的Action不能直接去访问各种拦截器栈吧,那我们得找一个代理代替我们干这活吖
而该方法又调用了ActionInvocation.invoke()方法
然后调用DefaultActionInvocation的invoke()//通过不断的回调这个方法,调用了所有拦截器,直到调用完
ActionInvocation就是Action的调用者。
ActionInvocation在Action的执行过程中,负责Interceptor、Action和Result等一系列元素的调度。
*/
public String invoke() throws Exception {
String profileKey = "invoke: ";
try {
UtilTimerStack.push(profileKey);

if (executed) {
throw new IllegalStateException("Action has already executed");
}

if (interceptors.hasNext()) {//拦截器集合,不断的回调,
final InterceptorMapping interceptor = interceptors.next();
String interceptorMsg = "interceptor: " + interceptor.getName();
UtilTimerStack.push(interceptorMsg);
try {
resultCode = interceptor.getInterceptor().intercept(DefaultActionInvocation.this);
}
finally {
UtilTimerStack.pop(interceptorMsg);//拦截器回调完后,最终通过这个方法来调用Action类方法
}
} else {
resultCode = invokeActionOnly();
}
1Action请求流程:
每次发生一个Action请求时,并不是把立刻跳到相应的Action中,而是先生成一个Action实例,
把Action实例的属性都放入值栈中的栈顶,此时放入值栈的Action对象的属性还是没有赋值的,
再继续生成Actionproxy(代理)实例,由ActionProxy调用所有的拦截器,直到调用接 Parameters 拦截器将把表单字段映射到 ValueStack 栈的栈顶对象的各个属性中.
然后当执行到Action相对应的方法,为Action类的各个属性赋值
2Action类的对象在controller中实例化,并且利用OGNL方式进行自动赋值
1)声明需要用到的Action类对象
2)实现ModelDriver接口,实现getModel方法,并在getModel方法里实例化Action类对象,并返回实例化的对象(ps:不能直接的返回new Action()对象)

转载于:https://my.oschina.net/JeremySoftware/blog/687036

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值