SSH 環(huán)境搭建完整教程
SSH 環(huán)境搭建:struts2.18+spring2.5+hibernate3
一、SSH 環(huán)境搭建開發(fā)環(huán)境
1、Fileànewàweb project;
2、配置好TomCat;
二、SSH 環(huán)境搭建的配置structs
1、引入structs的包:
- struts2-config-browser-plugin-2.1.8.1.jar
- struts2-core-2.1.8.1.jar
- struts2-dojo-plugin-2.1.8.1.jar
- struts2-spring-plugin-2.1.8.1.jar(structs與spring整合添加的包)
2.修改WEB-INF下的web.xml,增加struts2的配置。增加代碼如下:這些配置代碼對于struts2是不變的,直接復(fù)制到web.xml即可。
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- </filter-class>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
3.添加src下添加struct.xml文件(見圖1)
注意:<result name="success" ..../>這部分,若type="redirect"將容易丟失很多信息,
若要傳入上下文信息,盡量不用,或者用type = "dispatcher"
4.在src/test包下添加action文件(見圖2)
5.添加jsp文件(見圖3)
二.Hibernate配置
1.用hibernate逆向工程,生成實體類文件和操作數(shù)據(jù)庫的dao類文件;分別復(fù)制到 test.model下,和test.service下,(不用建hibernate.cfg.xml)如下圖:(見圖4)
2.在spring的配置文件applicationContext.xml中增加以下內(nèi)容:在spring bean中注冊數(shù)據(jù)庫連接的datasouce以及sessionfactory;指定hibernate生成的實體類映射文件的具體位置;(見圖5)
3.在test.config下添加文件 serviceContext.xml 用于將 所有的set函數(shù)注冊到spring bean 里;(見圖6)
4.(見圖7)
(見圖8)
小結(jié):
SSH 環(huán)境搭建完整教程的內(nèi)容介紹完了,希望通過本文SSH 環(huán)境搭建內(nèi)容的學(xué)習(xí)能對你有所幫助!