Struts2+Spring+Hibernate搭建详解(包含代码)-13页word资料 下载本文

内容发布更新时间 : 2024/4/27 20:51:37星期一 下面是文章的全部内容请认真阅读。

Struts2+Spring+Hibernate搭建全解!

Struts2+Spring+Hibernate是J2EE的最新流行框架。本篇是我搭建这个框架的经验总结,有很多人搭建这个框架总会遇到

大大小小的问题,网上也没有什么行之有效的方案或成体系的介绍,所以我就决定总结一下我的搭建过程。给一些搭

建尚存问题的朋友提供帮助。

我用这个框架,实现的是基本的CRUD功能的一个雇员管理系统,本来打算丰富一下功能,但是一直没能抽出空去搞。

目前版本暂定为1.0,除了CRUD外还配置了表单验证框架JSValidation。功能都能很顺利的实现。 现在分享部分源码,来说明一些注意事项。 以下是部分搭建过程及源码:

1.先组合实现Hibernate3.2+Spring2.5支持,删除hibernate.cfg.xml文件,修改applicationContext.xml文件的内容,增加SessionFactory和dataSource的设置。 2.通过MyEclipse的向导方式,生成POJO类和对应的映射文件。

3.修改applicationContext.xml文件中

5.修改applicationContext.xml文件,增加对Dao实现类的配置。

6.组合Struts2和Spring2.5,修改web.xml文件,增加struts2的所需要的过滤器配置。 7.增加struts2相应类库,增加struts2与spring的配置jar包。

8.拷贝struts.xml文件到src根目录下,再修改struts.xml文件,进行常量配置。

9.修改web.xml文件,配置Spring监听器,和上下文变量。并增加OpenSessionInViewFilter的设置。 10.写入action类。 11.配置struts.xml文件。 12.修改applicationContext.xml 13.编写Jsp文件。 14.加载运行项目。 下面是关键文件的源码: struts.xml源码:

\ \>

第 1 页

add.action /emp/add_suc.jsp

/emp/list.jsp

delete.action /emp/delete_suc.jsp

update.action /emp/edit_suc.jsp

/emp/edit.jsp

web.xml源码:

第 2 页

http://java.sun/xml/ns/javaee/web-app_2_5.xsd\

contextConfigLocation

/WEB-INF/applicationContext*.xml

org.springframework.web.context.ContextLoaderListener

lazyLoadingFilter

org.springframework.orm.hibernate3.support.OpenSessionInViewFilter

struts2

org.apache.struts2.dispatcher.FilterDispatcher

lazyLoadingFilter *.action

第 3 页