ssh,


(1)使用DelegatingRequestProcessor

在struts-config.xml中:

 

<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>

 完成这个配置后,struts会将拦截到的用户请求转发到Spring context下的Bean,根据Bean的name 属性来匹配。struts中的action配置无需再配置type属性

 

(2)使用ActionSupport

spring本身也提供了struts的相关类,在BaseAction中调用ActionSupport中的getWebAppicationContext()的方法取出WebAppicationContext,进而取出各种service

(3)让spring可以反向控制struts中的Action

对于Action,可以像管理Bean一样管理,在struts-config.xml中action中action配置:

 

<action attribute="aForm" name="aForm" path="/aAction" scope="request" type="org.springframework.web.struts.DelegatingActionProxy">
   <forward name="forward" path="forward.jsp">
</action>

之后需要建立action-servlet.xml

 

 

<bean name="/aAction" class="com.web.action.Aaction" singleton="false">
   <property name="businessService">
     <ref bean="businessService"/>
   </property>
</bean>

  <1>com.web.action.Aaction是Action的实现类,businessService是需要的业务逻辑

 

  <2>Spring会把businessService注入到Action 中,在Action中只需写businessService的get和set方法

  <3>singlon="false",每次新建一个实例,解决了Struts中Action的线程同步问题

流程:

   当用户做/aAction的http请求,struts会找到这个Action对应类org.springframework.web.struts.DelegatingActionProxy,这个代理类,会去找action-servlet.xml文件中“/aAction”对应的真正实现类,然后把它实例化,同时把需要的业务对象注入,然后执行Action的excute()

相关内容

    暂无相关文章