`
aaagu1234
  • 浏览: 150969 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

               ...

<bean id="LoginAction" class="cn.edu.jlu.cs.action.LoginAction" />
分享到:
评论

相关推荐

    struts spring集成【下】

    通过以上步骤,我们可以成功地将Struts2和Spring集成在一起,利用Spring的强大功能管理Action类、事务以及其他的业务逻辑,同时保持Struts2的MVC架构清晰易用。这种集成方式提高了代码的可测试性,降低了耦合度,...

    struts2-spring-plugin-2.5.13.jar

    搭建struts2 + spring框架时需要使用的关联jar struts.xml中action的属性class引用applicationContext中bean的属性id指向的值

    整合struts2和spring源代码(可以直接在tomcat中运行)

    当创建一个对象的时候,它会用Struts2配置文件中的class属性去和Spring配置文件中的id属性进行关联,如果能找到,则由Spring创建,否则由Struts 2框架自身创建,然后由Spring来装配。Spring插件具体有如下几个作用:...

    struts+spring文件上传大小限制.rar

    当Struts和Spring一起使用时,文件上传的处理通常在Action类中完成,这里需要集成Spring的`@Autowired`注解和Struts的`ActionForm`。Spring的`@RequestParam`注解可以用来获取`CommonsMultipartFile`对象。同时,...

    Struts2整合Spring.docStruts2整合Spring.doc

    Struts2 整合 Spring 是一个常见的 Java Web 开发中的集成技术,主要目的是利用 Spring 提供的依赖注入(Dependency Injection, DI)和控制反转(Inversion of Control, IoC)来管理 Struts2 中的 Action 类,使得...

    Struts2的总结和Strut2集成Spring

    OGNL可以用在Struts2的标签、配置文件和Action中,用于动态生成HTML代码、配置属性值和执行业务逻辑。 #### Struts2新表单 Struts2提供了一些新的表单标签,如`&lt;s:checkboxlist/&gt;`, `&lt;s:doubleselect/&gt;`和`...

    Struts2的常量详解

    struts.objectFactory.spring.useClassCache 属性指定整合 Spring 框架时,是否缓存 Bean 实例,该属性只允许使用 true 和 false 两个属性值,它的默认值是 true。 7. struts.objectTypeDeterminer struts....

    struts2+hibernate_spring的整合说明文档

    这样,当Struts2需要创建Action实例时,它会从Spring容器中查找并使用已配置好的bean。 5. **Action类的Spring管理** 在`applicationContext.xml`中,你需要定义Action类的bean,包括它的依赖和其他属性。例如: ...

    Struts2属性文件详解

    指定了Struts 2生成URL时是否包含请求参数,可接受`none`、`get`和`all`三个属性值,分别对应于不包含、仅包含GET类型请求参数和包含全部请求参数。 #### struts.custom.i18n.resources 指定了Struts 2应用所需的...

    Struts2整合spring的步骤.txt

    - 在`struts.xml`中定义Action及其对应的方法时,可以通过`class`属性指定具体的Bean名称: ```xml &lt;action name="userAction" class="userAction"&gt; &lt;result&gt;/success.jsp &lt;/action&gt; ``` 通过以上步骤,可以...

    struts2+hibernate+spring经典整合实例教程

    3. **框架集成**:涵盖 Struts2、Spring 和 Hibernate 的集成过程。 4. **配置文件详解**:重点解析配置文件的编写与作用。 5. **功能实现**:以用户登录功能为例展示整合效果。 #### 环境搭建 本教程选用 ...

    myeclipse6中整合struts2和spring框架

    - **Struts2 配置**:在 `struts.xml` 文件中配置 `&lt;package&gt;`,使用 `&lt;action&gt;` 标签的 `class` 属性指向 Spring Bean 的全限定类名。 #### 12.5 实现文件上传下载 文件上传和下载是 Web 应用中常见的需求。...

    struts+spring ioc 实例

    在这个实例中,我们将看到如何将Struts的动作(Action)类与Spring的IoC容器集成,以便通过设值注入(Setter Injection)来管理依赖。设值注入是Spring的一种注入方式,它通过调用对象的setter方法来设置依赖的对象...

    struts2+hibernate3.2+spring2.5集成方案

    Struts2与Spring的整合则涉及Action类的定义和Spring的DispatcherServlet配置,以及Struts2的struts.xml文件配置,以便Struts2能够识别并调用Spring管理的Action类。 这个集成方案的实现涉及到了多层架构的设计,...

    struts hibernate spring 知识点

    Struts2的标签`s:property value=“”`可以方便地将Action中的属性值输出到页面上。 8. 解决中文乱码问题,可以在struts2的配置文件中添加一个常量`&lt;constant name="struts.i18n.Encoding" value="GBK"&gt;`,设定字符...

    第十二章 开发Struts 2+Spring应用.pdf

    ### 第十二章 开发Struts 2+Spring应用 #### 12.1 引言 在本章节中,我们将探讨如何使用Struts 2框架与Spring框架进行整合开发,以便构建更为灵活、可扩展的企业级Java Web应用程序。Struts 2作为Struts 1的后续...

    Struts2+Spring3+Hibernate3整合文档

    需要注意的是,这里的`class`属性值是指向`applicationContext.xml`中定义的Bean ID,而不是实际的Java类。 ##### 2.4 Action的Scope配置 由于Struts2中的Action对象是针对每个请求生成一个新的实例,而Spring默认...

    struts2取到页面的值

    以下将详细解析Struits2中获取页面值的方法,包括基本类型参数的获取、复杂对象属性的映射以及Spring框架集成下的依赖注入。 ### 基本类型参数的获取 当页面通过表单提交一个简单的字符串或数字时,可以在Action类...

    struts_spring_hibernate_extjs4_笔记

    这里的`resource`属性值指向了实体类对应的Hibernate映射文件(.hbm.xml)。映射文件中定义了对象-关系映射的详细信息。 【Spring配置】 Spring是另一个核心Java EE框架,提供依赖注入(DI)和面向切面编程(AOP)...

    struts2核心配置文件

    - **struts.objectTypeDeterminer**:指定Struts2的类型检测机制,支持 `tiger` 和 `notiger` 两种属性值。 5. **文件上传配置**: - **struts.multipart.parser**:指定处理multipart/form-data MIME类型的框架...

Global site tag (gtag.js) - Google Analytics