struts2同樣支援客戶端驗證
1. struts2標籤的form的主題(theme)一定不能設為******。
2. 將form的validate屬性設為true。
這樣客戶端就會根據相應的action的xml驗證檔案產生乙個js對客戶端進行驗證。
一般開發中只使用struts2的服務端驗證,而不使用struts2的客戶端驗證,因為它的格式太死板。
我們可以自己寫js來進行客戶端的驗證。
regist2.jsp
username
password
re-password
struts2的action中可以有多個方法,若我們只想對其中的乙個方法進行驗證的話,可以提供如下檔案:
如對registaction中的test方法進行驗證,須要registaction-test-validation.xml檔案,路徑與其action一至。
若同時出現registaction-test-validation.xml與registaction-validation.xml兩個檔案,則會先執行registaction-tvalidation.xml的校驗,再執行registaction-test-validation.xml的校驗。
若出現繼承的action時,如:
parrentaction
parrentaction-validation.xml
parrentaction-test-validation.xml
childaction extence parrentaction
childaction-validation.xml
childaction-test-validation.xml
若要對childaction中的test方法進行驗證,則系統會按照以上檔案的順序進行4次驗證。
Struts2 獲取客戶端請求引數
struts2是乙個優秀的mvc model view controller 框架,其中客戶端請求引數在mvc架構中作為model的屬性存在。struts2框架有兩種方式獲取客戶端請求的引數。1 通過屬性驅動的方式獲取客戶端請求的引數 將action類作為model的方式 1 將pojo類作為act...
struts2客戶端校驗器詳解
一 struts2內建校驗器 位於xwork 2.0.4.jar壓縮包中 com.opensymphony.xwork2.validator.validators 有個檔案default.xml 該檔案中定義了struts2框架內建的校驗器。default.xml檔案定義了常用的校驗器型別。二 各種...
Struts2驗證框架
action配置中一定要設定input返回頁面 新增驗證只要建立驗證的xml檔案 在action同包下,建立 action類名 validation.xml 如 validateaction建立validateaction validation.xml 注意 1.要驗證的方法不能叫input.2.這...