2013-10-22 71 views
0

我必須通過struts 1中的反射實現攔截器。 攔截器出現在Struts 2中,並且在struts 1中沒有攔截器,但有一些方法可以實現這種行爲。我發現了2種方式:攔截器在Struts中的實現1

  1. Struts的Action調用框架(SAIF): http://struts.sourceforge.net/saif/#interceptor-class 但是有關於它的很少信息。

  2. AOP(方面:org.aspectj)

什麼是解決這個問題的最好方法是什麼?還有其他方法嗎?

+0

也許你可以在你的web.xml寫過濾器。這與攔截器的行爲幾乎相同。 –

+0

我認爲這並不是我所需要的,因爲過濾器在某些操作之前執行了某些功能,但我必須記錄此操作 –

回答

0

編輯:我沒有注意到這個問題有多大,抱歉。

那麼,如果你不使用Struts 1,我會爲此推薦Spring框架。如果你想使用Spring(3.2.9)的版本(不太舊),它可以在Struts 1中使用。雖然你在它,看看春天MVC :)

春天有優秀的AOP支持,因爲它的大部分「魔術」是用AOP執行的。

下面是記錄方法的入口和出口記錄儀的一個例子:

<aop:config> 
    <aop:advisor advice-ref="loggingAdvisor" 
     pointcut="execution(public * com.example.*(..))" /> 
</aop:config> 
<bean id="loggingAdvisor" 
    class="org.springframework.aop.interceptor.CustomizableTraceInterceptor"> 
    <property name="loggerName" value="logger-name" /> 
    <property name="enterMessage" value="Entering $[methodName]($[arguments])" /> 
    <property name="exitMessage" value="Leaving $[methodName](): $[returnValue]" /> 
</bean>