Spring笔记⑥--整合struts2

Spring如何在web应用里面用

  1. 需要额外加入的jar包

    Spring-web-4.0.0

    Spring-webmvc-4.0.0

  2. Spring的配置文件,没什么不同

?

需要在web.xml下配置,使用myeclipse2014可自动生成


?

<!-- 启动ioc容器的servletcontextLin -->

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

?

<!-- 配置spring文件的位置 -->

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:applicationContext.xml</param-value>

</context-param>

?

配置好bean后


<body>

<%

//1.从application域对象中得到IOC容器的实例

ApplicationContext ctx=WebApplicationContextUtils.getWebApplicationContext(application);

?

//2.从IOC容器中得到bean

Person p=ctx.getBean(Person.class);

?

//3.使用bean

p.hello();

?

?

%>

?

?

如何整合struts2

目的:使ioc容器来管理struts2的Action

?

在spring的ioc容器中配置struts2的Action

注意:在IOC容器中配置struts2的Action时,配置scope属性,其值必须为prototype


<bean
id="personService"
class="com.test.spring_web.service.PersonService"></bean>

????

????<bean
id="personAction"
class="com.test.spring_web.action.PersonAction"

????????scope="prototype">

????????<property
name="personService"
ref="personService"></property>

????</bean>

?

配置struct2 的配置文件;action节点的class属性需要指向IOC容器中该bean的


<action
name="person-save"
class="personAction">

????????<result>/success.jsp</result>

????</action>

?

注意需要加入文件

?

时间: 2024-08-10 19:17:19

Spring笔记⑥--整合struts2的相关文章

Spring框架整合Struts2使用Validation框架验证表单用户输入数据的详细教程

原创整理不易,转载请注明出处:Spring框架整合Struts2使用Validation框架验证表单用户输入数据的详细教程 代码下载地址:http://www.zuidaima.com/share/1778685765291008.htm 在<Struts2教程4:使用validate方法验证数据>中曾讲到使用validate方法来验证客户端提交的数据,但如果使用validate方法就会将验证代码和正常的逻辑代码混在一起,但这样做并不利于代码维护,而且也很难将过些代码用于其他程序的验证.在St

spring之整合struts2

首先将以下jar包加入到lib文件夹中: 基础目录: Person.java package com.gong.spring.struts2.beans; public class Person { private String username; public void setUsername(String username) { this.username = username; } public void hello(){ System.out.println("My name is &q

Spring框架整合Struts2

1,用Spring架构,及Struts2-spring-plugin插件 导入Spring的dist全部所需的jar包 Struts2的spring插件 struts2-spring-plugin.XX.jar struts2的核心包 struts2-core.XX.jar xwork- core.XX.jar commons.logging.XX.jar ...根据需要选择导入 2,配置web.xml中applicationContext.xml的参数路径及侦听器 <context-param

Spring笔记⑤--整合hibernate代码测试

String整合hibernate代码测试 在上节生成的表中插入数据: ? 注意:使用myeclipse2014生成的整合项目可能存在问题需要我们自己导入. ? 第一步 我们写dao接口 package com.ssh.spring_hibernate.dao; ? public interface BookShopDao { ????//根据书号获取数的单价 ????public int findBookPriceByIsbn(String isbn); ???? ????//更新书的库存,使

Spring整合Struts2

Spring整合Struts21整合目的:让Spring的IOC容器去管理Struts2的Action, 2Struts2是web开源框架,Spring要整合Struts2,也就是说要在web应用使用Spring①. 需要额外加入的 jar 包:spring-web-4.0.0.RELEASE.jarspring-webmvc-4.0.0.RELEASE.jar ②. Spring 的配置文件, 和非 WEB 环境没有什么不同 ③. 需要在 web.xml 文件中加入如下配置: <!-- 配置

struts2+hibernate+spring简单整合且java.sql.SQLException: No suitable driver 问题解决

最近上j2ee的课,老师要求整合struts2+hibernate+spring,我自己其实早早地有准备弄的,现在都第9个项目了,无奈自己的思路和头绪把自己带坑了,当然也是经验问题,其实只是用myeclipse进行整合的,本来也没那么多问题,看视频吧居然好多要手打,我不喜欢看不下去放弃了,教程把就是一堆坑,最最让人不解的是明明有一个冲突是需要解决的,但我看到的教程居然都没有提到,还有一个错误居然好多人都好像自动忽略一样,能解决我问题的都是要漫长的找,所以我一定一定要把这个过程记录下来,给第一次搞

Spring与Struts2整合VS Spring与Spring MVC整合

Spring与Struts2整合,struts.xml在src目录下 1.在web.xml配置监听器 web.xml <!-- 配置Spring的用于初始化ApplicationContext的监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <contex

Spring学习(八)spring整合struts2

一.spring框架对struts等表现层框架的整合原理 : 使用spring的ioc容器管理struts中用于处理请求的Action 将Action配置成ioc容器中的bean 延伸:spring对持久层框架/技术的整合原理 (封装) : 提供模板类封装对应技术/框架的开发流程 通过对模板类的使用,实现对传统开发流程的"代替". 二.整合方式: 插件方式 struts2为了实现对spring框架整合,也提供了一个插件的配置文件struts-plugin.xml struts2-spr

struts2+hibernate-jpa+Spring+maven 整合(2)

之前的一篇已经讲到了 spring 与struts2 的整合, 其实对于struts2+hibernate-jpa+Spring 之间的整合的文章已经相当多了, 也相当成熟了,只要不是各自的版本不兼容之外,其他的几乎没啥问题, 不行mybatis那样是不是的冒点让人头疼的事情来 下面修改pom.xml ,把hibernate 的jar 关联进来; <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="