I believe I can fly
蟲蟲的Blog
BlogJava
::
首頁
::
新隨筆
::
聯系
::
聚合
::
管理
::
8 隨筆 :: 2 文章 :: 2 評論 :: 0 Trackbacks
<
2009年6月
>
日
一
二
三
四
五
六
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(2)
給我留言
查看公開留言
查看私人留言
隨筆檔案
2009年6月 (4)
2009年5月 (1)
2009年4月 (3)
文章檔案
2009年6月 (1)
2008年9月 (1)
搜索
最新評論
1.?re: JDK安裝步驟
評論內容較長,點擊標題查看
--myandroider
2.?re: JDK安裝步驟
這個jdk安裝寫得很好,很具體,對我這個初學者來說幫了大忙了,謝謝了
--趙云
閱讀排行榜
1.?MAP泛型使用方法(3517)
2.?fatjar導出的jar文件雙擊執行時提示could not find the main class(3193)
3.?SSH開發測試時出現Socket Closed錯誤(1967)
4.?MySql修改字段的限制條件(1459)
5.?覆寫hashCode和compareTo方法時出現"無法取消引用"的錯誤(764)
評論排行榜
1.?Struts中的Action使用request不當導致前端無法找到相應的屬性(0)
2.?fatjar導出的jar文件雙擊執行時提示could not find the main class(0)
3.?MySql修改字段的限制條件(0)
4.?Struts+Hibernate+Spring組合開發的環境搭建(0)
5.?SSH開發測試時出現Socket Closed錯誤(0)
Struts+Hibernate+Spring組合開發的環境搭建
由于SSH組合開發在實際的大型項目中是用得最多的,所有SSH的環境搭配對于開發人員來說也是比較重要的。
SSH的環境搭配主要包括兩個方面:Struts與Spring的組合;Hibernate與Spring的組合.
SSH的組合工作主要有兩步:導入需要的Jar包;實現SSH的組合
第一步,導入需要的Jar包
在MyEclipse中,導入SSH的順序應該是Spring、Hibernate、Struts。
導入的操作比較簡單,其中最需要注意的就是在導入Hibernate的時候要選擇通過Spring的applicationContext.xml文件對Hibernate進行管理,即不需要創建hibernate.cfg.xml的原因。這也是為什么Spring在Hibernate之前導入的原因了。
第二步,實現SSH的組合,這也是SSH組合的重點
首先是Struts與Spring的組合,他們的組合無非就是將Struts的Action交給Spring管理,這需要添加一個插件,在struts-config.xml文件中生成等如下的代碼:
1
<
plug
-
in
2
className
=
"
org.springframework.web.struts.ContextLoaderPlugIn
"
>
3
<
set
-
property property
=
"
contextConfigLocation
"
4
value
=
"
/WEB-INF/classes/applicationContext.xml
"
/>
5
</
plug
-
in
>
在上述代碼中是添加了一個ContextLoaderPlugIn插件,并添加了一個屬性contextConfigLocation,其指向的是/WEB-INF/classes/applicationContext.xml,即Spring的控制文件,除此之外,還需要添加一個controller,所以最終在struts-config.xml文件生成的代碼為:
1
<
controller
2
processorClass
=
"
org.springframework.web.struts.DelegatingRequestProcessor
"
>
3
</
controller
>
4
5
<
plug
-
in
6
className
=
"
org.springframework.web.struts.ContextLoaderPlugIn
"
>
7
<
set
-
property property
=
"
contextConfigLocation
"
8
value
=
"
/WEB-INF/classes/applicationContext.xml
"
/>
9
</
plug
-
in
>
其中的controller的作用是對所有的Struts的請求都叫給Spring管理。
struts-config.xml文件修改完了以后,還需要在web.xml文件中添加一個context-param,具體代碼如下:
1
<
context
-
param
>
2
<
param
-
name
>
contextConfigLocation
</
param
-
name
>
3
<
param
-
value
>
4
/
WEB
-
INF
/
classes
/
applicationContext.xml
5
</
param
-
value
>
6
</
context
-
param
>
這一點是與struts-config.xml文件中的plugin中的屬性相對應的。
到此為止,Struts與Spring的組合搭配就算完成了。
然后就是Hibernate與Spring的搭配了,現在的applicationContext.xml文件應該為如下的內容:
1
<
bean id
=
"
dataSource
"
2
class
=
"
org.springframework.jndi.JndiObjectFactoryBean
"
>
3
<
property name
=
"
jndiName
"
value
=
"
java:comp/env/jdbc/demo
"
></
property
>
4
</
bean
>
5
<
bean id
=
"
sessionFactory
"
6
class
=
"
org.springframework.orm.hibernate3.LocalSessionFactoryBean
"
>
7
<
property name
=
"
dataSource
"
>
8
<
ref bean
=
"
dataSource
"
/>
9
</
property
>
10
<
property name
=
"
hibernateProperties
"
>
11
<
props
></
props
>
12
</
property
>
13
</
bean
>
在上述代碼中,應在sessionFactory的HibernateProperties屬性中添加相應內容,最后的效果如下:
1
<
bean id
=
"
sessionFactory
"
2
class
=
"
org.springframework.orm.hibernate3.LocalSessionFactoryBean
"
>
3
<
property name
=
"
dataSource
"
>
4
<
ref bean
=
"
dataSource
"
/>
5
</
property
>
6
<
property name
=
"
hibernateProperties
"
>
7
<
props
>
8
<
prop key
=
"
hibernate.dialect
"
>
9
org.hibernate.dialect.MySQLDialect
10
</
prop
>
11
<
prop key
=
"
hibernate.connection.autocommit
"
>
true
</
prop
>
12
<
prop key
=
"
hibernate.show_sql
"
>
true
</
prop
>
13
</
props
>
14
</
property
>
15
<
property name
=
"
mappingResources
"
>
16
<
list
>
17
</
list
>
18
</
property
>
19
</
bean
>
接著在applicationContext.xml文件添加如下的節點:
1
<
bean id
=
"
hibernateTemplate
"
2
class
=
"
org.springframework.orm.hibernate3.HibernateTemplate
"
>
3
<
property name
=
"
sessionFactory
"
>
4
<
ref bean
=
"
sessionFactory
"
/>
5
</
property
>
6
</
bean
>
最后是在web.xml文件添加對session的管理代碼:
1
<
filter
>
2
<
filter
-
name
>
opensession
</
filter
-
name
>
3
<
filter
-
class
>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</
filter
-
class
>
4
</
filter
>
5
<
filter
-
mapping
>
6
<
filter
-
name
>
opensession
</
filter
-
name
>
7
<
url
-
pattern
>*
.jsp
</
url
-
pattern
>
8
</
filter
-
mapping
>
完成這一步以后呢,那么整個SSH組合的搭配基本也就結束了,你就可以利用Spring的強大功能完成對Struts和Hibernate的控制了。
在以后的文章中我會介紹這樣組合以后如何使用各個框架,以上這些也是我在學習SSH的過程中的一些總結吧,希望能對各位同樣的JAVA愛好有一定的幫助。
QQ交流群:90623790
posted on 2009-06-22 00:13
蟲蟲
閱讀(439)
評論(0)
編輯
收藏
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
Powered by:
BlogJava
Copyright © 蟲蟲
主站蜘蛛池模板:
亚洲一级毛片免观看
|
免费人成视频在线播放
|
国产免费变态视频网址网站
|
日本一区二区在线免费观看
|
亚洲ⅴ国产v天堂a无码二区
|
久久WWW色情成人免费观看
|
希望影院高清免费观看视频
|
亚洲高清毛片一区二区
|
中文字幕精品亚洲无线码二区
|
亚洲综合日韩中文字幕v在线
|
成人性生交大片免费看无遮挡
|
一区二区三区免费视频播放器
|
亚洲欧洲自拍拍偷午夜色
|
全亚洲最新黄色特级网站
|
朝桐光亚洲专区在线中文字幕
|
久热综合在线亚洲精品
|
日美韩电影免费看
|
99热在线观看免费
|
亚洲免费观看网站
|
亚洲日韩在线中文字幕第一页
|
大学生一级毛片免费看
|
最近免费字幕中文大全
|
亚洲精品自偷自拍无码
|
亚洲AⅤ无码一区二区三区在线
|
久久久久久夜精品精品免费啦
|
特级毛片A级毛片免费播放
|
亚洲av极品无码专区在线观看
|
亚洲一区二区三区自拍公司
|
日本免费的一级v一片
|
成年黄网站色大免费全看
|
中文字幕乱码一区二区免费
|
黄色a三级三级三级免费看
|
亚洲av专区无码观看精品天堂
|
亚洲国产精品高清久久久
|
av无码东京热亚洲男人的天堂
|
国产三级在线观看免费
|
一区二区免费视频
|
a级片免费在线播放
|
a级毛片免费高清视频
|
青娱乐在线视频免费观看
|
亚洲精品无码一区二区
|