搜档网
当前位置:搜档网 › SSH框架搭建步骤

SSH框架搭建步骤

struts+spring+hibernate框架集成
1、搭建struts框架
(1)创建一个web project
(2)添加struts类库
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
freemarker-2.3.15.jar
ognl-2.7.3.jar
struts2-core-2.1.8.1.jar
xwork-core-2.1.6.jar
(3)添加struts配置文件
在src下创建一个struts.xml配置文件
作用: 放置struts框架通用信息
(4)struts2与web project集成
在web.xml文件中添加struts2过滤器

struts
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter


struts
/*

(5)完成页面跳转
测试struts2框架是否成功
_____
(6)方便管理在|项目|下创建一个源文件
—————
源文件名叫:config:主要放置项目中所有的配置文件,
对配置文件统一管理
(7)strut2配置文件统一管理
(a) 在源文件夹下,创建一个struts包放置struts2所有配置文件
方便统一管理
(b)修改web.xml文件,加载struts2底层需要的配置文件

...

config
struts-default.xml,struts-plugin.xml,struts/struts.xml


(8)在struts.xml中添加struts2的常量
常量值分为开发模式和生产模式






(9)项目划分模块创建不同struts配置文件
(a)在config源文件下创建struts-user.xml文件
(b)在struts.xml引入 struts-user.xml

(10)测试项目

2、struts+spring集成
(1)添加spring类库
spring.jar
log4j-1.2.15.jar
dom4j-1.6.1.jar
commons-logging.jar
cglib-nodep-2.1_3.jar
(2)添加spring配置文件
在源文件config下创建spring包
放置所有与spring有关配置文件

applicationContext.xml放置于spring开发
有关的公共信息
(3)添加log4j配置文件
在源文件config目录下创建一个log4j.properties

(4)spring与web project集成
在web.xml文件中配置:


org.springframework.web.context.ContextLoad

erListener



contextConfigLocation
classpath:spring/applicationContext.xml

作用:用户请求,spring容器完成对象实例化
(5)struts2集成spring
作用:struts2去spring容器查找容器实例化的对象
(a)添加struts2集成spring插件
struts2-spring-plugin-2.1.8.1.jar
(b)添加struts2对spring支持
在struts.xml文件中添加常量

(c)struts2中action让spring容器管理
在applicationContext.xml中装配action

(d)修改struts.xml文件,让struts2中action完全让spring
容器管理

注意:struts中class值要与spring 中id相同
struts会根据class名字去spring容器查找
对象
(6)测试struts与spring集成

3 struts+hibernate+spring集成
(a)添加类库
antlr-2.7.6.jar
commons-collections-3.1.jar
hibernate3.jar
javassist-3.9.0.GA.jar
jta-1.1.jar
slf4j-api-1.5.8.jar
slf4j-nop-1.5.8.jar

添加数据驱动类库
mysql-connector-java-5.1.16-bin.jar
(b)创建实体类
User.java
(c)添加hibernate配置文件
在源文件config下创建包
hibernate.cfg
hibernate.cfg.xml
hibernate.hbm
*.hbm.xml
(d)对象模型生成关系模型
在项目工程中创建一个test源文件
作用:放置所有测试文件,方便统一管理
com.tarena.util.hibernate.ExportUtil

(e)spring与hibernate集成
spring管理hibernate映射文件
hibernate.cfg.xml
*.hbm.xml



































相关主题