Struts2工作原理:
1.初始化一個指向servlet容器的請求。
2.請求經(jīng)過web.xml中配置的過濾器過濾,F(xiàn)ilterDispatcher(struts2控制器的核心)詢問ActionMapper是否需要調(diào)用某個Action來處理這個請求。如果ActionMapper決定需要調(diào)用某個Action,F(xiàn)ilterDispatcher則把請求的處理交給ActionProxy。
3.ActionProxy通過配置文件Struts.xml配置文件找到需要調(diào)用的Action類。
4.ActionProxy創(chuàng)建一個ActionInvocation實例,同時ActionInvocation通過代理模式調(diào)用Action。但在調(diào)用之前,ActionInvocation會根據(jù)配置加載Action相關(guān)的所有Interceptor(攔截器)。
5.Action執(zhí)行完畢后,ActionInvocation負(fù)責(zé)根據(jù)struts.xml中的配置找到對應(yīng)的返回結(jié)果result。