




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 市场管理服务合同范本5篇
- 湖州安吉县卫生健康系统下属事业单位招聘考试真题2024
- 2025广西百色市田阳区消防救援大队政府招聘专职消防员9人考前自测高频考点模拟试题附答案详解
- 2025年智能制造与工业自动化融合
- 2025江西赣州市第五人民医院劳务派遣招聘助理护士20人模拟试卷及参考答案详解
- 2025年智能音箱的跨平台兼容性技术
- 2025年海洋能发电技术产业技术创新与知识产权保护报告
- 2025年安阳市疾病预防控制中心公开招聘工作人员15名模拟试卷附答案详解(模拟题)
- 2025江苏苏州高新区狮山横塘街道招聘15人模拟试卷(含答案详解)
- 2025年龙南市属事业单位考试试卷
- 足金点钻工艺培训
- JJG 162-2019饮用冷水水表
- 山西省煤矿安全生产管理人员培训考试题库(浓缩500题)
- 空调负荷计算-空调负荷的计算(空调工程)
- 计算机视觉之图像分类课件
- 输电线路工程安全风险识别、评估、预控措施
- 大学英语三级词汇表(新版)
- GB/T 18380.22-2008电缆和光缆在火焰条件下的燃烧试验第22部分:单根绝缘细电线电缆火焰垂直蔓延试验扩散型火焰试验方法
- 初中语文古诗词教学策略课件
- 视频安防监控技术交底
- 部编版六年级道德与法治上册第5课《国家机构有哪些》精品课件【带视频】
评论
0/150
提交评论