国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項超值服

開通VIP
struts2注解驅(qū)動 零配置
一、配置web.xml 
<filter> 
<filter-name>struts2</filter-name> 
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 
<init-param> 
<param-name>actionPackages</param-name> 
<param-value>com.test.action</param-value> 
</init-param> 
</filter> 

<filter-mapping> 
<filter-name>struts2</filter-name> 
<url-pattern>/*</url-pattern> 
</filter-mapping> 

二、加入注解 
@Namespace(value="/test") 
@Action(value = "file-manager", 
interceptorRefs = { 
@InterceptorRef(value = "fileUpload",params={"maximumSize","1024000","allowedTypes","image/pjpeg"}), 
@InterceptorRef(value = "basicStack")}, 
results = {@Result(name = ActionSupport.SUCCESS, location = "/view/file-manager-sucess.jsp"), 
@Result(name = ActionSupport.ERROR, location = "/view/file-manager-error.jsp") }, 
exceptionMappings = {@ExceptionMapping(exception = "java.lang.Exception", result = ActionSupport.ERROR)} 
) 

驗證注解: 
@Validations( 
requiredStrings={ 
@RequiredStringValidator(fieldName="username",message="用戶名不能為空!"), 
@RequiredStringValidator(fieldName="telNum",message="電話號碼不能為空!") 
}, 
regexFields={@RegexFieldValidator(fieldName="telNum",expression="^(\\+86|0|1)\\d{10,11}$", 
message="電話號碼格式不正確!")} 
) 

跳過驗證注解: 
@SkipValidation 

三、Convention的Annotation 
1)與Action相關(guān)的兩個Annotation是@Action 和@Actions 
2)@Action中可指定一個value屬性。類似于指定<action name=””/>屬性值 
3)@Action中還可以指定一個params屬性,該屬性是一個字符串?dāng)?shù)組,用于該Acion指定的參數(shù)名和參數(shù)值。params屬性應(yīng)遵守如下格式:{“name1”,”value1”,”name2”,”value2”} 
4)@Actions 也用于修飾Action類里的方法,用于將該方法映射到多個URL.@Actions用于組織多個@Action.因此它可將一個方法映射成多個邏輯Action。 

四、與Result配置相關(guān)的Annotation 
1)@ResultPath @Result 和Results 
2)@Results用于組織多個@Result因此它只需指定一個value屬性值,該value屬性值為多個@Result 
3)@Result相當(dāng)于struts.xml文件中的<result/>元素。使用@Result必須指定一個name屬性,相當(dāng)于<result name=””/>另外,它還有幾個可選的屬性。 
     ☆ type 相當(dāng)于<result type=””/>指定返回視圖資源的類型 
     ☆ location 相當(dāng)于<result>…..</result>中間部分,用于指定實際視圖位置 
     ☆ params:該屬性相當(dāng)于<result/>元素里多個<param../>子元素的作用,用于為該Result指定參數(shù)值。該屬性應(yīng)滿足{“name1”,”value1”,”name2”,”value2”}格式 
4)@Result有以下兩種用法 
1.Action級的Result映射:以@Actions組合多個@Action后修飾的Action類。這種Result映射對該Action里的所有方法都有效。 
2.方法級Result映射:將多個@Result組成數(shù)組后作為@Action的results屬性值。這種Result映射僅對被修飾的方法有效。 
5)@ResultPath則用于修飾包和Action類,用于改變被修飾Action所對應(yīng)的物理視圖資源的根路徑。舉例說:默認(rèn)情況下,Convention都會到WEB-INF/content路徑下找物理視圖資源,一旦我們使用@ResultPath("/view")修飾該Action,系統(tǒng)將回到view目錄下尋找物理視圖資源。 

五、與包和命名空間相關(guān)的Annotation: 
@Namespace:修飾Action類或其所在的包。該Annotation中指定一個value屬性值,用于指定被修飾的Action所在的命名空間 
@Namespaces:修飾Action類或其所在的包,用于組合多個@Namespace 
@ParentPackage: 用于指定被修飾的Action所在包的父包。 

六、與異常處理相關(guān)的Annotation 
@ExceptionMappings 用于組織多個@ExceptionMapping,因此它只需指定一個value屬性值,該value屬性值為多個@ExceptionMapping。 
@ExceptionMapping 用于定義異常類和物理視圖之間的對應(yīng)關(guān)系,也相當(dāng)于struts.xml文件里<exception-mapping../>元素的作用 使用時,必須注意以下兩個屬性: 
exception: 用于指定異常類 
result:用于指定邏輯視圖 
@ExceptionMpping有如下兩種用法 
Action級的異常定義:以@ExceptionMappings組合多個@ExceptionMapping后修飾的Action類。這種異常定義對Action中的所有方法有效 
方法級的異常定義:將多個@ExceptionMapping組成數(shù)組后作為@Action的exceptionMappings屬性值,這種異常定義僅對被修飾的方法有效。 

七、與攔截器配置相關(guān)的Annotation 
與攔截器配置的Annotation有@InterceptorRef、@InterceptorRefs和@DefaultInterceptorRef 
@InterceptorRefs用于組織多個@InterceptorRef,因此它只需要指定一個value屬性值,該value屬性值為多個@InterceptorRef 
@InterceptorRef用于為指定Action引用lanjieq或者是攔截器棧。也就相當(dāng)于strut.xml中位于<action../>元素內(nèi)部的<interceptor-ref../>子元素的作用。使用@InterceptorRefAnnotation時,必須制定一個value屬性,用于指定所引用的攔截器或攔截器棧的名字。相當(dāng)于<interceptor-ref../>子元素里name屬性的作用。 

八、查看struts2配置 
為了看到struts2應(yīng)用里的Action等各種資源的影射情況,struts2提供了Config Browser插件。 
使用方法:將struts2-config-browser-plugin-2.1.6.jar文件復(fù)制到struts2應(yīng)用的WEB-INF\lib目錄中。 
打開首頁地址:http://localhost:8080/應(yīng)用名字/config-browser/actionNames.action 這里可以看到Config Browser插件的首頁。 
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
簡述STRUTS2 Convention零配置
struts2采用注解方式配置url和Action的映射
Annotation(四)
Struts2 注解配置Action(十九)
使用struts2.5版本遇到的問題
STRUTS2.0 常用標(biāo)簽 struts2標(biāo)簽 struts2 - 未來客 - Java...
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服