ActionProxyFactory:
create ActionProxy factory,create ActionInvocation,create ActionProxy
ActionProxy:
serves as client code's handle to execute an action,it holds an ActionInvocation which reprents the current satate of the execution of the action.ActionProxy is created by a ActionProxyFactory in a dispatcher.ActionProxy sets up the execute context for the ActionInvocation and then calls invoke() on the ActionInvocation.
ActionInvocation: reprents the current state of the execution of the action,it holds the action instance ,the interceptors to be applied,the map of results,and an ActionContext.
ActionContext: which includes the request parameters,the application map ,the session map,the Local, and the ServletRequest and ServletResponse.
执行过程如下:
(1)在web.xml中指定的ServletDispacter或者FilterDispatcher,负责调用ActionProxyFactory完成ActionProxy的创建,
ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, context);
(2)ActionProxy 为ActionInvocation设定执行环境上下文,并调用ActionInvocation的invoke()方法
(3)关键在于ActionInvocation的invoke()方法,
public String invoke() throws Exception {
if (executed) {
throw new IllegalStateException("Action has already executed");
}
if (interceptors.hasNext()) { // notice here is if ,not while
InterceptorMapping interceptor = (InterceptorMapping) interceptors.next();
/** 调用拦截器的方法,将ActionInvocation作为参数
* 在intercept(this);中回调invoke() 方法,是一种递归的方式
*/
resultCode = interceptor.getInterceptor().intercept(this);
} else {
resultCode = invokeActionOnly();//当没有了拦截器没有调用时就invokeAction!然后返回!因为是递归调用的!然后按反顺序返回进行剩下的没完成部分...
}
// 做结果返回前的处理
// this is needed because the result will be executed, then control will return to the Interceptor, which will
// return above and flow through again
if (!executed) {
if (preResultListeners != null) {
for (Iterator iterator = preResultListeners.iterator();
iterator.hasNext();) {
PreResultListener listener = (PreResultListener) iterator.next();
listener.beforeResult(this, resultCode);
}
}
// now execute the result, if we're supposed to
if (proxy.getExecuteResult()) {
//执行结果的返回
executeResult();
}
executed = true;
}
return resultCode;
}
分享到:
相关推荐
#### 二、JavaAction执行机制 根据官方文档,JavaAction将会执行指定主Java类中的`public static void main(String[] args)`方法。Java应用程序将以单个Mapper任务的形式在Hadoop集群中执行。工作流任务会等待Java...
### Struts2运行机制详解 #### 一、Struts2框架概述 Struts2是一个基于MVC(Model-View-Controller)设计模式的Java Web应用框架,它为开发者提供了构建可扩展、易于维护的Web应用程序的工具。Struts2不仅继承了...
本篇文章将深入解析Struts1框架的执行原理,以及Action、ActionServlet、ActionForm三个关键组件的工作机制。 首先,我们来看Struts1的工作流程: 1. 用户通过浏览器发起HTTP请求,请求的目标是应用中的一个JSP或...
### JSP 文件运行机制详解 #### 一、JSP 文件的基本概念 JSP(Java Server Pages)是一种基于Java技术的动态网页技术标准。它允许在HTML文档中嵌入Java代码和表达式,使得Web页面能够根据请求动态生成内容。通过...
当 type 为 chain 时,说明是 action 链,运行完第一个 action java 文件接着会运行第二个 action JAVA 文件,相当于 forward(客户端的 url 不会改变)。这个 result 调用另外的一个 action,连接自己的拦截器栈和 ...
20. `ACTION_EMBED`:允许Activity在其他Activity中内嵌运行,常用于实现组件嵌入。 21. `ACTION_EMERGENCY_DIAL`:拨打紧急电话,如911或112等,用于紧急情况。 22. `ACTION_MAIN`:通常与`CATEGORY_LAUNCHER`...
#### 一、Action执行机制的不同 - **Struts1**: 在Struts1框架中,Action是基于单例模式的,这意味着所有的请求都会共享同一个Action实例。这就导致了如果在Action中保存实例变量,则可能会出现线程安全问题。此外...
- **Action执行机制**:除了默认的`execute`方法之外,还可以通过配置文件或URL参数来指定执行特定的方法。 **实践案例解析**: - **获取路径信息**:在Action中可以通过`HttpServletRequest`对象获取当前请求的上...
在Struts框架中,通常通过配置文件(struts.xml)定义Action,并且在用户请求到达时,框架会根据请求参数匹配相应的Action执行逻辑。然而,在某些场景下,我们希望在不进行任何用户交互的情况下就执行某些逻辑,比如在...
综上所述,Struts的运行机制是通过配置文件、控制器组件(ActionServlet和RequestProcessor)、ActionForm以及Action对象的交互来实现对客户端请求的处理,并将处理结果呈现给用户。这种机制使得开发者能够以一种...
Action参数传递是指在一个Action执行完毕后,将其执行过程中生成的数据作为参数传递给下一个Action,使得后续Action能够利用这些数据继续执行。这种机制大大增强了测试脚本的灵活性和可维护性,特别是在处理需要多个...
拦截器是Struts2中的一个重要概念,它们按照配置的顺序在Action执行前后运行,提供诸如日志、权限检查、结果映射等功能。XWork的拦截器模型使得我们能灵活地扩展和定制框架的行为。 3. **类型转换(Type Conversion...
- **结果**:`result`元素用于定义Action执行成功后转向的目标页面,本例中为`/next.jsp`。 2. **创建对应的Action文件** - 按照传统Struts框架的做法,在项目的`webRoot`目录下创建一个名为`go.action`的空文件...
如果在Action执行过程中抛出异常,框架可以根据预先定义的映射规则,自动跳转到错误页面或者特定的处理流程,提高了错误处理的灵活性和统一性。 #### 映射机制的优势 - **提高代码的可维护性和可扩展性**:通过...
开发者可以根据需要组合和配置拦截器栈,这些拦截器会在Action执行前后按顺序执行。 视图组件在Struts2中得到了增强,例如,Struts2提供了一系列组件如updownselect、doubleselect、datetimepicker、token和tree等...
在Web开发中,我们经常需要通过用户交互来执行不同的业务逻辑。...总之,理解URL、Action、jsp以及表单提交的交互机制是Web开发中的基础技能。通过学习和实践,你将能够更有效地构建动态、响应式的Web应用程序。
总的来说,Struts 2.0的Action机制更加灵活,允许开发者自由设计业务逻辑处理类,同时提供了一系列的便利支持。通过继承`ActionSupport`,可以轻松地利用框架提供的功能,如错误处理、验证和国际化。此外,通过...
Intent是一种消息传递机制,用于启动其他组件(如Activity、Service或BroadcastReceiver)来执行特定任务。自定义Action允许开发者创建特定于应用的行为,使得组件间的交互更加灵活。例如,你可以定义一个...