




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【Struts2+Spring3+Hibernate3】SSH框架整合实现一、导入Spring3.0、Hibernate3.0、Struts2开发库。1.1 sping 所依赖工程 spring-framework-2.5.6distspring.jarlibcglibcglib-nodep-2.1_3.jarlibjakarta-commonscommons-logging.jarlibaspectjaspectjweaver.jar和aspectjrt.jar libj2eecommon-annotations.jar1.2 hibernate 所依赖工程 hibernate-distribution-3.3.2.GAhibernate3.jarlibrequiredjta-1.1.jar javassist-3.9.0.GA.jar dom4j-1.6.1.jar commons-collections-3.1.jar antlr-2.7.6.jar slf4j-api-1.5.8.jarlibbytecodecglibcglib-2.2.jar二级缓存可选liboptionaloscacheoscache-2.1.jar 同时需要把perties 拷贝到src 下二级缓存可选liboptionalehcacheehcache-1.2.3.jar 同时需要把projectetcehcache.xml二级缓存可选liboptionalc3p0 配置c3p0数据库连接池的使用 作用等同于apache的dbcp*使用hibernate注解:hibernate-annotations-3.4.0.GAhibernate-annotations.jarlibhibernate-commons-annotations.jarlibejb3-persistence.jar*若使用slf的日志还需要:slf4j-1.5.8slf4j-nop-1.5.8.jar1.3 struts2 所依赖工程 struts-lib目录下的:struts2-core-.jarxwork-core-2.1.6.jarognl-2.7.3.jarfreemarker-2.3.15.jarcommons-fileupload-1.2.1.jarcommons-io-1.3.2.jarstruts2-spring-plugin-.jaraopalliance-1.0.jarclassworlds-1.1.jarcommons-beanutils-1.7.0.jarcommons-chain-1.2.jarcommons-collections-3.2.jar 在hibernate中已经引用commons-digester-2.0.jarcommons-lang-2.3.jarcommons-logging-1.0.4.jar 此文件在spring中已存在commons-logging-api-1.1.jarcommons-validator-1.3.1.jarezmorph-1.0.3.jarjson-lib-2.1.jar 若使用json可选oro-2.0.8.jaroval-1.31.jar二、配置web.xml文件的内容,如下:需要把spring、strusts2框架注入到web容器(hibernate框架被spring集成,和web容器没有关系。所以不需要在web.xml中配置) index.jsp !- 如果spring配置文件被命名为applicationContext.xml,并且放在WEB-INF目录下,则不需要配置,因为ContextLoaderListenr 默认在WEB-INF目录下寻找名applicationContext.xml的文件 - contextConfigLocation /WEB-INF/applicationContext.xml 我的spring配置文件放在WEB-INF根目录下,文件名为springconfig.xml contextConfigLoaction /WEB-INF/springconfig.xml 或者: contextConfigLocation/WEB-INF/spring/*.xml Spring core configuration org.springframework.web.context.ContextLoaderListener struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 我的struts配置文件放在WEB-INF根目录下,文件名为action.xml config struts-default.xml,struts-plugin.xml,./action.xml struts2 *.action !- web容器增加字符集转换的过滤器,由于struts2框架解决了字符集转码,此配置可以注释掉 encoding org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 encoding /* - !- Spring OpenEntityManagerInViewFilter org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter Spring OpenEntityManagerInViewFilter /* -1.如上struts2的核心控制器filter也可配置为如下类:org.apache.struts2.dispatcher.FilterDispatcher2.FilterDispatcher和StrutsPrepareAndExecuteFilter、StrutsPrepareFilter三、Spring的配置文件applicationContext.xml的配置内容如下: /schema/beans /schema/beans/spring-beans-2.5.xsd /schema/tx /schema/tx/spring-tx-2.5.xsd /schema/aop /schema/aop/spring-aop-2.5.xsd /以上一段代码是为了声明式事务而引入的命名空间(spring事务处理的新特性:采用命名空间) !- 如果不配置Hibernate配置文件,就不需要该配置,否则使用配置文件,就不需要配置dataSource和其他的Property -org.hibernate.dialect.MySQLDialectupdate com/hzboy/orm/Userinfo.hbm.xml !- 用户DAO实现,实现方式:JDBC - 其中集成hibernate需要属性文件:pertiesdriverClassName=com.mysql.jdbc.Driverurl=jdbc:mysql:/localhost:3306/sshdemodb?useUnicode=true&characterEncoding=utf-8username=rootpassword=1234initialSize=1maxActive=500maxIdle=2minIdle=1需要配置hibernate的二级缓存,如使用ehcache:在src路径下加入ehcache.xml 1.Demo默认Hibernate的DataSource、HibernateProperties、MappingResources信息配置到applicationContext.xml文件中。如果使用Hibernate.cfg.xml配置这些信息,需要在applicationContext.xml文件中将configLocation这个属性去掉注释,将其他的property注释或删除。2.applicationContext.xml默认放在webRootWEB-INF路径下,如果想要将spring的配置文件移动到其他文件夹或修改名字,需要在web.xml中添加如下代码: 我的spring配置文件放在WEB-INF根目录下,文件名为springconfig.xml contextConfigLoaction /WEB-INF/springconfig.xml3.Demo默认Hibernate的DataSource、HibernateProperties、MappingResources信息配置到applicationContext.xml文件中。如果使用Hibernate.cfg.xml配置这些信息,需要在applicationContext.xml文件中将configLocation这个属性去掉注释,并将其他的property注释或删除。Hibernate.cfg.xml配置如下:updateorg.hibernate.dialect.MySQLDialectjdbc:mysql:/localhost:3306/mysshroot123com.mysql.jdbc.DriverMySQL四、配置struts2的配置文件struts.xml如下: /WEB-INF/page/message.jsp /WEB-INF/page/error.jsp /index.jsp /login.jsp /userlist.jsp /useradd.jsp 1.当使用spring管理struts2的 action时要注意需在struts2的action配置文件中添加如下代码:并且需要将struts2-spring-plugin-2.2.1.jar添加到classpath中去。2.如要将Struts2的默认配置文件struts.xml文件重命名或移动到WEB-INF到下去,需要在web.xml的struts2过滤器中添加如下代码: 我的struts配置文件放在WEB-INF根目录下,文件名为action.xml co
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 大润发营运知识培训课件
- 2025年太阳能空调系统合作协议书
- 展厅装修知识培训班课件
- 新疆公务员真题试卷
- DIY手工活动协议
- 水泥混凝土施工协议
- 培训学校安全防范应急预案(3篇)
- 尼尔斯骑鹅历险记课件
- 尚品宅配装修知识培训课件
- 2025年智能家居系统全国销售区域代理权合作协议样本
- (高清版)DGJ 08-102-2003 城镇高压、超高压天然气管道工程技术规程
- JJF(滇) 32-2024 医用水平旋转仪校准规范
- 课堂评价课件
- 解除共管账户协议书
- 心胸外科麻醉管理
- 医工交叉培养提升医疗人才的综合能力
- 《鸿蒙HarmonyOS应用开发基础》课件 第1-3章 初识鸿蒙、ArkTS(上)、ArkTS(下)
- TCCEAS001-2022建设项目工程总承包计价规范
- 2025年医院血透室人员培训计划
- 《消防员心理素质培养》课件
- 倍智tas人才测评系统题库及答案
评论
0/150
提交评论