Struts2攔截器架構(gòu)
攔截器架構(gòu)
攔截器的生命周期
通過看攔截器的源碼我們看到:攔截器的生命周期是隨項目的啟動而創(chuàng)建调榄,隨項目的關(guān)閉而銷毀
自定義攔截器
創(chuàng)建方式
創(chuàng)建方式1
圖片.png
創(chuàng)建方式2
圖片.png
創(chuàng)建方式3
圖片.png
攔截器API
放行
圖片.png
前后處理
圖片.png
不放行 直接跳轉(zhuǎn)到一個結(jié)果界面
圖片.png
不執(zhí)行后續(xù)的攔截器以及Action,直接交給Result處理結(jié)果吧黄,進行頁面跳轉(zhuǎn)
攔截器配置
注冊攔截器
<!--注冊攔截器-->
<interceptors>
<interceptor name="myInter3" class="cn.probuing.struts2lesson.interceptorself.MyInterceptor3"/>
注冊攔截器棧
<!--注冊攔截器棧-->
<interceptor-stack name="mystack">
引入自己的攔截器和默認攔截器
<!--引入自己的攔截器-->
<interceptor-ref name="myInter3"/>
<!--引入默認的攔截器棧-->
<interceptor-ref name="defaultStack"/>
指定默認攔截器棧
<!--指定默認攔截器棧 指定包中默認的攔截器棧-->
<default-interceptor-ref name="mystack"/>
單獨為action指定攔截器
<action name="Interceptor" class="cn.probuing.struts2lesson.interceptorself.Interceptor1Demo">
<!--為action單獨指定走哪個攔截器棧-->
<!--<interceptor-ref name="mystack"/>-->
<result name="success" type="dispatcher">/index.jsp</result>
</action>
定制攔截方法
<interceptor-ref name="myInter3">
<!--指定哪些方法攔截哪些方法不攔截-->
<param name="excludeMethods">add,delete</param>
<!--指定哪些方法攔截 exclude include 只能有一個-->
<!--<param name="includeMethods">update,find</param>-->
</interceptor-ref>
Struts2標(biāo)簽
歷史
標(biāo)簽來源
標(biāo)簽結(jié)構(gòu)
圖片.png
控制標(biāo)簽
遍歷標(biāo)簽
<%--遍歷標(biāo)簽--%>
<%--遍歷方式1--%>
<s:iterator value="#list">
<%--取棧頂?shù)脑?-%>
<s:property/><br>
</s:iterator>
<%--遍歷方式2--%>
<s:iterator value="#list" var="name">
<s:property value="#name"/>
<br>
</s:iterator>
<%--計數(shù)--%>
<s:iterator begin="1" end="100" step="1">
<s:property/>
</s:iterator>
判斷標(biāo)簽
<!-- 判斷標(biāo)簽 -->
<s:if test="#list.size()==4">
<br>
list的長度為4
</s:if>
<s:elseif test="#list.size()==4">
<br>
list的長度為3
</s:elseif>
<s:else>
list 不3不4
</s:else>
數(shù)據(jù)標(biāo)簽 property
圖片.png
表單標(biāo)簽
表單標(biāo)簽
非標(biāo)單標(biāo)簽
圖片.png
圖片.png