1、流程分析: 1. 請求發送給 StrutsPrepareAndExecuteFilter 2. StrutsPrepareAndExecuteFilter 詢問 ActionMapper: 該請求是否是一個 Struts2 請求(即是否返回一個非空的 ActionMapping 對象) 3. 若 ...
1、流程分析:
- 請求發送給 StrutsPrepareAndExecuteFilter
- StrutsPrepareAndExecuteFilter 詢問 ActionMapper: 該請求是否是一個 Struts2 請求(即是否返回一個非空的 ActionMapping 對象)
- 若 ActionMapper 認為該請求是一個 Struts2 請求,則 StrutsPrepareAndExecuteFilter 把請求的處理交給 ActionProxy
- ActionProxy 通過 Configuration Manager 詢問框架的配置文件,確定需要調用的 Action 類及 Action 方法
- ActionProxy 創建一個 ActionInvocation 的實例,併進行初始化
- ActionInvocation 實例在調用Action的過程前後,涉及到相關攔截器(Intercepter)的調用。
- Action 執行完畢,ActionInvocation 負責根據 struts.xml 中的配置找到對應的返回結果。調用結果的 execute 方法,渲染結果。在渲染的過程中可以使用Struts2 框架中的標簽。
- 執行各個攔截器 invocation.invoke() 之後的代碼
- 把結果發送到客戶端
- 時序圖
- 相關的幾個 API
ActionMapping
:- Simple class that holds the action mapping information used to invoke a Struts action. The name and namespace are required
ActionMapper
:- When given an HttpServletRequest, the ActionMapper may return null if no action invocation request matches, or it may return an ActionMapping that describes an action invocation for the framework to try
ActionProxy
:- ActionProxy is an extra layer between XWork and the action so that different proxies are possible.
ActionInvocation
:- An ActionInvocation represents the execution state of an Action. It holds the Interceptors and the Action instance. By repeated re-entrant execution of the invoke() method, initially by the ActionProxy, then by the Interceptors, the Interceptors are all executed, and then the Action and the Result.
- An ActionInvocation represents the execution state of an Action. It holds the Interceptors and the Action instance. By repeated re-entrant execution of the invoke() method, initially by the ActionProxy, then by the Interceptors, the Interceptors are all executed, and then the Action and the Result.