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
...
<bean id="LoginAction" class="cn.edu.jlu.cs.action.LoginAction" />
假如: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
...
<bean id="LoginAction" class="cn.edu.jlu.cs.action.LoginAction" />
本文介绍了Struts2框架在独立使用与集成Spring框架时,action实例创建的区别及配置文件的不同。具体展示了struts.xml中action配置的变化,并指出在集成环境下,action实例由Spring负责创建。
381

被折叠的 条评论
为什么被折叠?



