第七章:Struts2驗證機(jī)制_第1頁
第七章:Struts2驗證機(jī)制_第2頁
第七章:Struts2驗證機(jī)制_第3頁
第七章:Struts2驗證機(jī)制_第4頁
第七章:Struts2驗證機(jī)制_第5頁
已閱讀5頁,還剩49頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、IBM Software Group 2008 IBM CorporationIBM Software Group第七章:Struts 2驗證機(jī)制主講:劉雷主講:劉雷IBM Software GroupIBM Software Group本章內(nèi)容Struts2輸入基礎(chǔ)校驗應(yīng)用輸入校驗的重要性、Struts2輸入校驗的實現(xiàn)方式手動編程實現(xiàn)輸入校驗校驗框架實現(xiàn)輸入校驗Struts2輸入校驗高級用法自定義校驗器visitor校驗器的應(yīng)用方法IBM Software GroupIBM Software GroupStruts2輸入校驗基礎(chǔ)為什么要使用輸入校驗?Struts2中的輸入校驗手動編程方式:主

2、要是通過在類中編寫校驗邏輯代碼使用struts2校驗框架:把校驗邏輯放到配置文件中,實現(xiàn)校驗邏輯代碼與業(yè)務(wù)邏輯代碼的分離。手動編程方式方式一:重寫validate()方法,在struts2框架中,專門用來校驗數(shù)據(jù)的方法是validate()方法。開發(fā)者可以通過繼承ActionSupport類,并重寫validate()方法來完成輸入校驗。方式二:重寫validateXxx()方法:在struts2框架中,Action中可以包含多個處理邏輯,也就是類似于execute的多個方法,只是方法名不同,在struts.xml文件中配置Action時,可以指定method屬性,框架將根據(jù)屬性值來執(zhí)行相應(yīng)的

3、邏輯。Struts2框架允許在Action中提供一個validateXxx()方法,專門校驗xxx()這個處理邏輯。例如,有一個處理邏輯為regist()的方法,在Action中,就可以使用validateRegist()方法來校驗這個處理邏輯。IBM Software GroupIBM Software Group手動編程方式(一):重寫validate()方法register.jspIBM Software GroupIBM Software GroupValidateInExecute.java省略了省略了setter()/getter()方法方法IBM Software GroupIB

4、M Software Groupstruts.xml文件IBM Software GroupIBM Software Group手動編程方式(二)重寫validateXxx()方法省略了省略了setter()/getter()方法方法struts.xml與與register.jsp見上述見上述PPTIBM Software GroupIBM Software Group手動編程方式(三)省略了省略了setter()/getter()方法方法IBM Software GroupIBM Software GroupIBM Software GroupIBM Software Groupstruts

5、.xml配置文件register.jsp見上述見上述PPTIBM Software GroupIBM Software GroupStruts2內(nèi)置校驗器IBM Software GroupIBM Software Group校驗器配置風(fēng)格(一)IBM Software GroupIBM Software Group校驗器配置風(fēng)格(二)IBM Software GroupIBM Software Group驗證框架注意通常要對哪個Action驗證就需要給出相應(yīng)的XxxAction-validation.xml文件,例如,如果要對UserAction進(jìn)行驗證就需要UserAction-valid

6、ation.xml文件配置如果要對同一個UserAction的不同方法reg()與login()分別進(jìn)行驗證,如何做呢?這時需要給出二個不同的驗證文件:命名規(guī)則如下: UserAction-reg-validation.xml和UserAction-login-validation.xml但是請注意UserAction-reg-validation.xml和UserAction-login-validation.xml中的reg與login不是指的reg()和login()的方法名,而是指在struts.xml中配置的action配置的name屬性的名字.IBM Software GroupI

7、BM Software Group必填校驗器requiredIBM Software GroupIBM Software Grouprequired校驗器示例IBM Software GroupIBM Software Grouprequired校驗器示例IBM Software GroupIBM Software Grouprequired校驗器示例IBM Software GroupIBM Software Grouprequired校驗器示例此實例要先訪問action,因為訪問action時,字段內(nèi)容為空IBM Software GroupIBM Software Grouprequir

8、edstring校驗器IBM Software GroupIBM Software Grouprequiredstring校驗器示例IBM Software GroupIBM Software Grouprequiredstring校驗器示例IBM Software GroupIBM Software Grouprequiredstring校驗器示例IBM Software GroupIBM Software Groupstringlength校驗器示例IBM Software GroupIBM Software Grouprequiredstring校驗器示例IBM Software Gro

9、upIBM Software Groupint校驗器IBM Software GroupIBM Software Groupint校驗器示例IBM Software GroupIBM Software Groupint校驗器示例IBM Software GroupIBM Software Groupint校驗器示例IBM Software GroupIBM Software Groupconversion校驗器IBM Software GroupIBM Software Groupconversion校驗器示例IBM Software GroupIBM Software Groupdate校驗

10、器IBM Software GroupIBM Software Groupdate校驗器示例IBM Software GroupIBM Software Groupdate校驗器示例IBM Software GroupIBM Software Groupdate校驗器示例IBM Software GroupIBM Software Groupemail與url校驗器IBM Software GroupIBM Software Groupemail與url校驗器示例IBM Software GroupIBM Software Groupemail與url校驗器示例IBM Software Gro

11、upIBM Software Groupemail與url校驗器示例IBM Software GroupIBM Software Groupexpression與fieldexpression校驗器IBM Software GroupIBM Software Groupexpression與fieldexpression校驗器示例IBM Software GroupIBM Software Groupexpression與fieldexpression校驗器示例IBM Software GroupIBM Software Groupexpression與fieldexpression校驗器示例

12、IBM Software GroupIBM Software Groupfieldexpression校驗器示例IBM Software GroupIBM Software Groupdouble校驗器IBM Software GroupIBM Software Groupdouble校驗器示例IBM Software GroupIBM Software Groupregex校驗器IBM Software GroupIBM Software Groupregex校驗器示例IBM Software GroupIBM Software Group自定義校驗器IBM Software GroupIBM Software Group自定

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論