<bean id="check" class="quanquanfly.Check"/>
<bean name="/test" class="quanquanfly.TestAction" >
</bean>
<aop:config>
<aop:aspect id="checkaa" ref="check">
<aop:pointcut id="all" expression="execution(* quanquanfly.TestAction.add(..))"/>
<aop:before method="aa" pointcut-ref="all"/>
</aop:aspect>
</aop:config><form-beans>
<form-bean name="testactionform" type="quanquanfly.TestActionForm" />
</form-beans> <action-mappings> <action path="/test" type="org.springframework.web.struts.DelegatingActionProxy" name="testactionform"
scope="request" validate="false" parameter="command">
<forward name="success" path="/aa.jsp" />
</action>
</action-mappings>
public class Check {
public void aa()
{
System.out.println("aaaaa");
}
}
然后我在页面action="test.do?command =add"的时候后台怎么不打印aaaaa的?aop无法拦截add?
<bean name="/test" class="quanquanfly.TestAction" >
</bean>
<aop:config>
<aop:aspect id="checkaa" ref="check">
<aop:pointcut id="all" expression="execution(* quanquanfly.TestAction.add(..))"/>
<aop:before method="aa" pointcut-ref="all"/>
</aop:aspect>
</aop:config><form-beans>
<form-bean name="testactionform" type="quanquanfly.TestActionForm" />
</form-beans> <action-mappings> <action path="/test" type="org.springframework.web.struts.DelegatingActionProxy" name="testactionform"
scope="request" validate="false" parameter="command">
<forward name="success" path="/aa.jsp" />
</action>
</action-mappings>
public class Check {
public void aa()
{
System.out.println("aaaaa");
}
}
然后我在页面action="test.do?command =add"的时候后台怎么不打印aaaaa的?aop无法拦截add?
你肯定得通过spring的容器来获得bean,然后你配置的aop才能起作用啊。。
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-*.xml</param-value>
</context-param>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean name="/test" class="quanquanfly.TestAction" >
<property name="Iuser" ref="userDao" />
</bean>
<!-- 应该把1放在这里吧-->
<aop:pointcut id="all" expression="execution(* quanquanfly.TestAction.add(..))"/>
<aop:aspect id="checkaa" ref="check">
<!-- <aop:pointcut id="all" expression="execution(* quanquanfly.TestAction.add(..))"/> --> <!-- 1-->
<aop:before method="aa" pointcut-ref="all"/>
</aop:aspect>
</aop:config>
能贴你的Action代码吗