锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 榪欎釜鎷︽埅鍣ㄩ潪甯哥畝鍗曘?code>before() 鏂規硶鍦ㄦ嫤鎴偣涓瘡涓柟娉曚箣鍓嶈繍琛屻傚湪鏈緥涓紝瀹冩墦鍗板嚭涓鍙ヨ瘽錛屽叾瀹炲畠鍙互鍋氭偍鎯沖仛鐨勪換浣曚簨銆備笅涓姝ュ氨鏄湪 Spring 閰嶇疆鏂囦歡涓敞鍐岃繖涓嫤鎴櫒錛屽娓呭崟 8 鎵紺猴細 鎮ㄥ彲鑳藉凡緇忔敞鎰忓埌浜嗭紝娓呭崟 8 鎵╁睍浜?娓呭崟 6 涓墍紺虹殑搴旂敤紼嬪簭浠ュ寘鍚竴涓嫤鎴櫒銆傚叿浣撶粏鑺傚涓嬶細
package ca.nexcel.books.interceptors;
import org.springframework.aop.MethodBeforeAdvice;
import java.lang.reflect.Method;
public class LoggingInterceptor implements MethodBeforeAdvice {
public void before(Method method, Object[] objects, Object o) throws Throwable {
System.out.println("logging before!");
}
}
娓呭崟 8. 鍦?Spring 閰嶇疆鏂囦歡涓敞鍐屾嫤鎴櫒
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="bookService" class="ca.nexcel.books.business.BookServiceImpl"/>
<bean name="/searchSubmit"
class="ca.nexcel.books.actions.SearchSubmit">
<property name="bookService">
<ref bean="bookService"/>
</property>
</bean>
<!-- Interceptors -->
<bean name="logger"
class="ca.nexcel.books.interceptors.LoggingInterceptor"/> |(1)
<!-- AutoProxies -->
<bean name="loggingAutoProxy"
class="org.springframework.aop.framework.autoproxy.
BeanNameAutoProxyCreator"> |(2)
<property name="beanNames">
<value>/searchSubmit</valuesgt; |(3)
</property>
<property name="interceptorNames">
<list>
<value>logger</value> |(4)
</list>
</property>
</bean>
</beans>
<value>
鏍囪銆?
]]>
struts.xml榪欐牱閰嶇疆
struts.properties鐨勯厤緗細
鐒跺悗鍐欎竴涓狟aseAction:
榪欐牱鍏朵綑鐨凙ction閮藉彲浠ョ洿鎺ョ戶鎵緽aseAction錛屼笉鐢ㄥ啀鍋氫換浣曢厤緗?
閫氳繃return render(target)杞彂鍒版寚瀹氱殑jsp欏甸潰,浠庤岄棿鎺ュ疄鐜伴浂閰嶇疆