SSH框架的构建
Struts 、 Spring 、 Hibernate 、 Tiles 、 validator 工具 :Eclipse3.1 、 MyEclipse 新建工程 oa jstl标签库很好用,所以也把它加载上 增加 Struts 框架 因为在整个架构中 Struts 属于 UI 层,所以将 struts 放入 com.oa.view 包中 增加 Spring 框架 将配置文件放入 /WEB-INF/ 目录内 在增加 Hibernate 框架之前,如果没有配置过数据连接的话,请打开 MyEclipse Database Exploring 视图 配置连接:以连接 MySql 为例 增加 Hibernate 框架 在配置选项中选择使用 Spring 的配置文件,并输入 sessionFactory Hibernate 属于 Data 层,所以将它放入 com.oa.data 包内 逻辑层的包为 com.oa.model 以下为目录结构 + src + --com.oa.data //数据层 + --com.oa.data.bo //BO对像和映射文件 + --com.oa.data.dao //DAO对像的接口 + --com.oa.data.dao.impl //DAO对像的实例 + --com.oa.model 逻辑层 + --com.oa.model.service // Service对像的接口 + --com.oa.model.service.impl //Service对像的实例 + --com.oa.view 视图层 + --com.oa.view.action // Action对像 + --com.oa.view.tag // 标签 集成框架: Spring 和 Hibernate 的集成已经由 MyEclipse 的向导完成 Struts 和 Spring 的集成将使用 Struts 插件的方式进行集成 Tiles 、 validator 和 Struts 的集成也是使用插件的方式 完整的配置文件如下 : <? xml version = "1.0" encoding = "UTF-8" ?> <! DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd" > < struts-config > < data-sources /> < form-beans /> < global-exceptions /> < global-forwards /> < action-mappings /> < message-resources parameter = "com.oa.web.struts.ApplicationResources" /> < plug-in className = "org.apache.struts.tiles.TilesPlugin" > < set-property property = "definitions-parser-validate" value = "true" /> < set-property property = "definitions-config" value = "/WEB-INF/tiles-config.xml" /> </ plug-in > < plug-in className = "org.apache.struts.validator.ValidatorPlugIn" > < set-property property = "pathnames" value = "/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" /> </ plug-in > < plug-in className = "org.springframework.web.struts.ContextLoaderPlugIn" > < set-property property = "contextConfigLocation" value = "/WEB-INF/applicationContext.xml,/WEB-INF/serviceContext.xml,/WEB-INF/ view Context.xml" /> </ plug-in > </ struts-config > 创建 tiles-config.xml 文件 , 内容如下 : <?xml version="1.0" encoding="UTF-8"?> <tiles-definitions> </tiles-definitions> 注意以下几点: 多个配置文件可用逗号分隔 Validator 的配置文件 "/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" ,这两个文件在 /WEB-INF/ 目录都没有, validator-rules.xml 文件需要从 struts 的包中拷贝过来 , validation.xml 文件需要自行创建 此文件中spring配置文件我将它分为三个,以区分三层结构中不同的配置,请不要直接在其它两个配置文件中写配置信息,最好是先将配置信息写入到 applicationContext.xml 中,因为只有在此文件中 MyEclipse 才会验证配置信息的合法性 还是以 Login 为例做一下测试 先将大概用到的包都创建好 将配置文件中提到的文件都准备好 先将 spring 的配置文件创建好,文件格式使用 applicationContext.xml 的样式,内容如下:
没有评论:
发表评论