struts2把action交给spring托管

来源:互联网 发布:中国网络资讯台无锡市 编辑:程序博客网 时间:2024/05/17 02:10

首先先看一下demo的大概结构

action类:

public class Myaction extends ActionSupport{private String name;private int age;private int test;........}
其中name,age由表单传过来的值确定,test由spring注入

spring托管action的主要流程

1.在spring配置文件中注入struts的action类

 <bean id="Myaction" class="com.action.Myaction" p:test="222"></bean>
2.在struts2配置文件中配置Action时,指定<action>的class属性为Spring配置文件中相应bean的id或者name值

<action name="Myaction*" class="Myaction" method="{1}"><result name="success">/pages/MyJsp.jsp</result></action>


可以看出struts的action其实是由spring容器创建的,所以它的test字段先被赋值,name/age字段在之后表单输入再赋值