10分鐘學懂Struts 2.0 攔截器
Struts 2.0攔截器
簡介 |
在Struts 2.0 中的攔截器,要實現com.opensymphony.xwork2.interceptor.Interceptor接口,在struts.xml中配置。可以用攔截器來完成調用Action業務邏輯之前的預處理或是之后的善后處理。還可以通過配置多個攔截器來滿足action需求。
Interceptor stack是由多個攔截器組成的攔截器組,在攔截器組中可以對每一個攔截器映射。所有進行配置攔截器時,不必對每一個攔截器進行配置,而只需對interceptor stack進行配置即可。在struts 2中默認配置了一個全局interceptor stack,包括Exception Interceptor、Validation Interceptor等。
實例 |
在這個實例當中,我將配置一個時間攔截器,用來統計每個action的請求時間。













































interceptordemo.jsp:






