关于struts2中与Spring中Action对象创建的问题

来源:互联网 发布:找不到导航软件怎么办 编辑:程序博客网 时间:2024/06/05 10:25
【原--】关于struts2中与Spring中Action对象创建的问题【原--】关于struts2中与Spring中Action对象创建的问题 
在struts2架构中,Action对象的创建、Action对象属性的赋值以及Action对象的销毁,都是由struts2自己
行维护的,无需程序员参与;
【原--】关于struts2中与Spring中Action对象创建的问题 
在Spring+struts2架构中,Action对象需要由Spring产生,而不是由struts2进行维护(struts2架构中是这
样);同时,在struts.xml配置文件中,指定Action的class时,指定的是一个具体的Action对象,而
不是一个Action类(struts2中是这样的),这个Action对象是在Spring的配置文件applicationContext.xml
中通过<bean/>标签进行配置的。之所以在struts2架构中将Action的class指定为Action类,而在Spring+struts2
架构中将Action的class指定为Action对象,原因在于在struts2架构中Action对象是由struts2自己维护的(程序员
无需参与)而在Spring+struts2架构中,Action对象是由Spring产生的(在applicationContext.xml通过<bean>
标签配置)。

总结:
1.Action对象的产生方式:
  •  struts2架构         : 由struts2进行维护,程序员无需参与;
  •  Spring+struts2架构:由Spring产生,在applicationContext.xml通过<bean>标签配置;
2.struts.xml中配置Action时,class的指定方式:
  •  struts2架构         :指定的是Action类;
  1. struts.xml文件
  2. ---------------------------------------------------------------------------------------------------------
  3. <action name="login" class="com.lyq.action.LoginAction"> //说明:LoginAction是一个Action类,而不是对象
  4. <result name="success">/welcome.jsp</result>
  5. </action>
  • Spring+struts2架构:指定的是Action对象,这个对象是在Spring的配置文件中进行配置的;
  1. struts.xml文件
  2. ---------------------------------------------
  3. <action name="*_cat" class="catAction">//说明:catAction是对象,不是类
  4. <result name="list">/form/list.jsp</result>
  5. </action>
上面catAction对象在Spring的配置文件applicationContext.xml中进行配置;
  1. applicationContext.xml文件
  2. ----------------------------------------------------------
  3. <bean id="catAction" scope="prototype"
  4. class="com.helloweenvsfei.spring.struct2.CatAction">
  5. <property name="catService" ref="catService"></property>
  6. </bean>

0 0
原创粉丝点击