Struts2搭建:1.導入jar包
2.複製sturuts2文件到項目
3.web.xml配置過濾器
1,Struts2框架介紹
Struts2框架是MVC流程框架,適合分層開發。框架應用實現不依賴於Servlet,使用大量的攔截器來處理用戶請求,屬於無侵入式的設計。
2,Struts2框架的流程原理
1)請求先到達Filter中央控制器
2)然後爲Action創建代理類
3)將各個服務存放在攔截器中,執行完攔截器後再去執行action類行action類,action類調用service,再調用dao
4)得到結果字符串,創建result對象
5)轉向相應的視圖。
程序流程圖如下:
3,框架的使用
框架爲我們做好了封裝,使用起來就按照步驟,配置幾個xml文件就行拉。
1)導入jar包
2)拷貝struts.xml文件
將拷貝的配置文件放在根目錄src下。struts.xml文件主要是配置請求路徑對應action類的,以及結果跳轉路勁。
3)在web.xml文件中配置核心控制器
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>