配置環境
1. 導入jar包,Struts2官網
2. 創建Action類 繼承ActionSupport
(ActionSupport類是一個工具類, 它已經實現了Action介面。 除此之外, 它還實現了Validateable介面, 提供了資料校驗功能。 通過繼承該ActionSupport類, 可以簡化Struts 2的Action開發。
)
3. Action配置:
1).在src資料夾下創建struts.xml設定檔
2).導入DTD文件:
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
DTD檔路徑:struts2-core-2.3.x.jar/struts-default.xml
3 ).創建根節點
4 ).在根節點
extends="struts-default"(值固定)
namespace="/" (可不寫, 預設值就是"/")
5 ).在
class="實現類的完整路徑";
method="方法名"(默認執行execute方法)
以上配置一個 返回值需要一個
例如:
6 ).在
type="dispatcher"(設定轉發還是重定向, 默認是轉發dispatcher, 重定向:redirect)
創建無返回值的方法:方法無返回資料類型(void)
02 return Action.NONE(NONE=NULL)
例如:
7 ). 全域結果頁面配置:
4. 在web.xml中配置篩檢程式
以上就是Struts2的設定檔配置方法啦!
· 學IT, 就來中公優就業:http://www.ujiuye.com/
· 2017年【中公教育】特別推出2017年就業促進計畫, 500萬就業基金助你成為IT達人
詳情請戳http://www.ujiuye.com/zt/jycj/?wt.bd=bgz
· 什麼?海量IT學習資料白給你都不要?別想了,