struts2与spring集成时action的class属性值意义

struts2单独使用时action由struts2自己负责创建;与spring集成时,action实例由spring负责创建(依赖注入)。这导致在两种情况下struts.xml配置文件的略微差异。

假如:LoginAction在包cn.edu.jlu.cs.action中。

1. struts2单独使用时,action的class属性为LoginAction的全路径名,如下:

               ...

<action name="login" class="cn.edu.jlu.cs.action.LoginAction">

           <result name="studentSuccess">

                /student/studentindex.jsp

           </result>

               ...

2. struts2与spring集成时,class属性是spring的applicationContext.xml中配置的bean的id属性值。

---------------------------------------------------------------------------------------

//struts.xml

               ...

<action name="login" class="LoginAction">

           <result name="studentSuccess">

                /student/studentindex.jsp

           </result>

               ...

----------------------------------------------------------------------------------------

//applicationContext.xml    或者在spring相应的配置文件中

               ...

<bean id="LoginAction" class="cn.edu.jlu.cs.action.LoginAction" />

原文地址:https://www.cnblogs.com/fanziyang/p/6106694.html