struts2課程知識點(diǎn)總結(jié)_第1頁
struts2課程知識點(diǎn)總結(jié)_第2頁
struts2課程知識點(diǎn)總結(jié)_第3頁
struts2課程知識點(diǎn)總結(jié)_第4頁
struts2課程知識點(diǎn)總結(jié)_第5頁
全文預(yù)覽已結(jié)束

下載本文檔

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

文檔簡介

struts2課程知識點(diǎn)總結(jié)bywanggc1.actiona)struts2環(huán)境配置包括5個(gè)基本jar包,web.xml中配置過濾器、struts.xml文件配置、編寫actionb)得到表單數(shù)據(jù)(接受參數(shù))兩種方法:1、getset方法2、對象c)動態(tài)方法配置action中定義方法名稱,strust.xml文件action中配置如:method=”add”d)簡單數(shù)據(jù)驗(yàn)證應(yīng)用addFieldError()(了解)e)默認(rèn)action的配置<default-action-refname="index"></default-action-ref>f)session等jsp內(nèi)置對象的應(yīng)用兩種方法1、普通2、mapg)action通配符的配置*與{}或*_*<actionname="Student*"class="example.StudentAction"method="{1}">2.resultResult四種返回類型:1、dispatcher2、redirect3、chain4、redirectAction<actionname="r1"><!—默認(rèn)類型,類似于jspforward,服務(wù)器端跳轉(zhuǎn)地址欄顯示為:action路徑http://localhost:8088/struts_0800_resulttype/r1.action <resulttype="dispatcher">/r1.jsp</result> </action> <actionname="r2"><!—客戶端跳轉(zhuǎn)地址欄顯示為:.jsp文件http://localhost:8088/struts_0800_resulttype/r2.jsp <resulttype="redirect">/r2.jsp</result> </action> <actionname="r3"><!—服務(wù)器端跳轉(zhuǎn)到另一個(gè)action <resulttype="chain">r1</result> </action> <!—客戶端跳轉(zhuǎn)到另一個(gè)action <actionname="r4"> <resulttype="redirectAction">r2</result></action>Result全局返回類型<global-results> <resultname="error">/error.jsp</result> </global-results>3.interceptor1、開發(fā)攔截器類,必須繼承AbstractInterceptor類并且重寫intercept()方法2、在struts.xml文件中定義此攔截器<interceptors> <interceptorname="authority"class="lee.AuthorityInterceptor"></interceptor> </interceptors>3、在action標(biāo)簽中配置應(yīng)用此攔截器<actionname="viewPrice"class="lee.PriceAction"><result>/index.jsp</result><resultname="login">/login.jsp</result><interceptor-refname="defaultStack"></interceptor-ref><interceptor-refname="authority"></interceptor-ref></action>4、ognl步驟:1、在action中定義成員變量2、為成員變量生成setget方法3、給成員變量賦值4、在jsp中通過<s:propertyvalue="username"/>標(biāo)簽取出此成員變量的值。JSP中取值的三種情況:1、在頁面中取得action中成員變量中的值<s:propertyvalue="username"/>2、取得對象的屬性值<s:propertyvalue="user.age"/><s:propertyvalue="user['age']"/>3、取得集合(List)中對象的屬性值訪問List中元素某個(gè)屬性的集合:<s:propertyvalue="dogs.{name}"/>5、tags(標(biāo)簽庫)引入:<%@tagliburi="/struts-tags"prefix="s"%>1、<form>標(biāo)簽<s:form><s:textfield<s:password<s:textarea<s:select<s:checkboxlist………2、控制標(biāo)簽<s:iftest="%{#frank[1]=='踢腳線'}"> <s:elseiftest="%{#frank[1]=='進(jìn)戶門套油漆2'}"> <s:else><s:iterator<s:append<s:generator<s:merge<s:sort<s:subset3、數(shù)據(jù)標(biāo)簽<s:bean<s:param<s:property<s:debug></s:debug><s:include<s:push<s:set<s:action6、Struts2類型轉(zhuǎn)換1、自動類型轉(zhuǎn)換2、list列表自動類型轉(zhuǎn)換3、類型轉(zhuǎn)換錯(cuò)誤提示定義AddMaterialAperties文件加入:invalid.fieldvalue.material.mount=\u5E93\u5B58\u8F93\u5165\u9519\u8BEF\uFF01<s:fielderror/>7、Struts2輸入校驗(yàn)1、action中重寫publicvoidvalidate()方法2、action中定義publicvoidvalidateXXX()方法XXX表示action中的方法名稱,此校驗(yàn)只對XXX()方法校驗(yàn)。如:對action中的Register方法校驗(yàn),則應(yīng)定義validateRegister()校驗(yàn)方法。注:第一種方法對所有action添加校驗(yàn)第二種方法只對XXX方法進(jìn)行校驗(yàn)3、通過定義xml校驗(yàn)文件進(jìn)行校驗(yàn)如:對RegisterAction校驗(yàn),在同級目錄下添加RegisterAction-validation.xml校驗(yàn)文件注:xml校驗(yàn)文件進(jìn)行校驗(yàn)有兩種方式1、*.jsp頁面文件中需要寫<s:formaction="Register.action"validate="true">2、*.jsp頁面文件中不需要寫validate="true"8、Struts2國際化支持步驟:1、JSP中配置<s:textfieldname="username"key="username"/>2、perties中配置struts.custom.i18n.resources=messageResource3、messageResource_en_US.properties(英語)中配置username=UserNamepassword=UserPasswordloginSubmit=login4、messageResource_zh_CN.properties(中文)中配置username=\u7528\u6237\u540Dpassword=\u5BC6\u7801loginSubmit=\u767B\u5F55username=//用戶名password=//密碼loginSubmit=//登錄5、測試改變?yōu)g覽器語

溫馨提示

  • 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)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論