struts 2 拦截器
生活随笔
收集整理的這篇文章主要介紹了
struts 2 拦截器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
對于常用的MVC框架來說,他們都會完成一些通用的控制邏輯,例如解析請求參數,類型轉換,權限控制等,struts 2的攔截器采取的是可插拔式的設計,如果我們需要使用某個攔截器,只需要在配置文件中應用改攔截器即可;如果不需要使用該攔截器,只需要在配置文件中取消應用該攔截器——不管是否應用某個攔截器,對于struts 2框架不會有任何影響。具體實現如下:
實現一個攔截器:
public class TestInterceptor extends AbstractInterceptor{@Overridepublic String intercept(ActionInvocation actionInvocation) throws Exception {System.out.println("進入Action之前,先攔截一次");String result = actionInvocation.invoke();System.out.println("執行完action方法之后,再攔截一次");return result;}}在struts.xml配置攔截器:
在struts.xml使用攔截器:
<action name="login" class="com.durendong.action.LoginAction"> <!--應用攔截器--> <interceptor-ref name="testInterceptor" /> <result name="success">/WEB-INF/content/login.jsp</result></action>
如需查看源代碼,點此下載
?
轉載于:https://my.oschina.net/durendong/blog/76192
總結
以上是生活随笔為你收集整理的struts 2 拦截器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Add Two Numbers
- 下一篇: DataGridVidw添加CheckB