Struts2運(yùn)行流程圖如下所示:

Struts2請(qǐng)求的處理步驟概述:
客戶端發(fā)送請(qǐng)求;請(qǐng)求經(jīng)過一系列過濾器(Filter),起主要作用的是StrutsPRepareAndExecuteFilter過濾器(另有可選過濾器ActionContextCleanUp用于和其他框架集成);調(diào)用FilterDispatcher,用于詢問 ActionMapper當(dāng)前該請(qǐng)求是否為Struts2請(qǐng)求(即是否返回一個(gè)非空的ActionMapping對(duì)象);若ActionMapper認(rèn)為該請(qǐng)求為Struts2請(qǐng)求,則FilterDispatcher將請(qǐng)求交給ActionProxy處理;ActionProxy通過Configuration Manager訪問框架的配置文件,確定需要調(diào)用的Action 類及Action方法;ActionProxy創(chuàng)建一個(gè)ActionInvocation的實(shí)例,并對(duì)其進(jìn)行初始化;ActionInvocation實(shí)例在調(diào)用Action的過程前后,涉及到相關(guān)攔截器(Intercepter)的調(diào)用;Action執(zhí)行完畢,ActionInvocation負(fù)責(zé)根據(jù)struts.xml中的配置找到對(duì)應(yīng)的返回結(jié)果;調(diào)用結(jié)果的execute()方法以渲染結(jié)果,渲染過程中可以使用Struts2框架所提供的標(biāo)簽;執(zhí)行各個(gè)攔截器invocation.invoke()之后的代碼,并返回結(jié)果到客戶端。附:相關(guān)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.新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注