在學習struts的時候,我們一定要掌握struts2的工作原理。只有當我們明確了在struts2框架的內部架構的實現過程,在配置整個struts 的框架時,可以很好的進行邏輯上的配置。接下來我就先簡單的講解下struts2的框架工作原理:
一、struts2的工作原理
1、客戶端初始化一個指向Servlet容器(例如Tomcat)的請求;
2、這個請求經過一系列的過濾器(Filter)(這些過濾器中有一個叫做ActionContextCleanUp的可選過濾器,這個過濾器對于Struts2和其他框架的集成很有幫助,例如:SiteMesh Plugin);
3、接著FilterDispatcher被調用,FilterDispatcher詢問ActionMapper來決定這個請求是否需要調用某個Action;
4、如果ActionMapper決定需要調用某個Action,FilterDispatcher把請求的處理交給ActionProxy;
5、ActionProxy通過ConfigurationManager詢問框架的配置文件,找到需要調用的Action類;
6、ActionProxy創建一個ActionInvocation的實例。
7、ActionInvocation實例使用命名模式來調用,在調用Action的過程前后,涉及到相關攔截器(Intercepter)的調用。
8、一旦Action執行完畢,ActionInvocation負責根據struts.xml中的配置找到對應的返回結果。返回結果通常是(但不總是,也可能是另外的一個Action鏈)一個需要被表示的JSP或者FreeMarker的模版。在表示的過程中可以使用Struts2框架中繼承的標簽。在這個過程中需要涉及到ActionMapper。
二、部署一個struts2項目的一般步驟
1)在Myeclipse中創建一個web項目,并將struts2需要的jar包導入進項目中,如下圖
2)在項目中的web.xml中進行配置struts2的框架,在web.xml中需要包含在<filter></filter>,在該節點下可以包含<filter-name>和<filter-mapin
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> </web-app>
本文名稱:Struts2的配置struts.xmlAction詳解-創新互聯
標題鏈接:http://vcdvsql.cn/article0/hdeio.html
成都網站建設公司_創新互聯,為您提供定制網站、微信小程序、關鍵詞優化、電子商務、域名注冊、網站排名
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯