小菜毛毛技術分享
與大家共同成長
BlogJava
::
首頁
::
聯系
::
聚合
::
管理
164 Posts :: 141 Stories :: 94 Comments :: 0 Trackbacks
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(15)
給我留言
查看公開留言
查看私人留言
我參與的團隊
隨筆分類
andriod(23)
appfuse 集成J2EE框架(2)
eclipse 插件相關(3)
English(5)
FckEditor(2)
FLEX(9)
google app engine(2)
googleAnalytics(1)
htmlunit(1)
httpclient(1)
IDE(8)
java基礎運用(11)
java定時器(5)
jQuery(1)
JSON-LIB快速入門(1)
JSTL(3)
LOG4J(1)
maven(1)
mysql(1)
servlet(3)
SMC(stateMachine)(1)
spring 框架(1)
struts2(1)
SVN(1)
tiles 框架(1)
velocity(1)
webservice(6)
XML(3)
協議相關(3)
應用服務器(5)
性能優化(3)
技術族譜:軟件開發相關知識體系的整理心得(圖)(1)
搜索引擎(5)
操作系統(4)
數據建模(8)
電信綜合施工調度系統-剖析(2)
規則引擎(1)
計算機基礎(1)
設計模式(2)
資源(2)
集群與負載均衡(2)
面試(37)
隨筆檔案
2011年5月 (1)
2011年2月 (1)
2011年1月 (2)
2010年12月 (7)
2010年11月 (18)
2010年10月 (7)
2010年9月 (8)
2010年8月 (4)
2010年7月 (5)
2010年6月 (4)
2010年5月 (7)
2010年4月 (8)
2010年3月 (24)
2010年2月 (12)
2010年1月 (7)
2009年12月 (2)
2009年11月 (3)
2009年10月 (2)
2009年9月 (8)
2009年8月 (15)
2009年7月 (13)
2009年6月 (2)
2009年5月 (4)
文章分類
AJAX(9)
ANT(4)
EXTJS(15)
HTML+div+css實踐(16)
J2EE相關技術與框架(26)
java基礎及其原理(9)
JBPM(9)
JSTL(2)
rbac 權限管理模型(1)
webservice(1)
XML(3)
個人日志(4)
技術類英文文檔翻譯學習(1)
數據庫(33)
數據結構
權限管理(2)
電信行業(2)
文章檔案
2010年9月 (1)
2010年5月 (1)
2010年3月 (3)
2010年2月 (12)
2010年1月 (17)
2009年12月 (9)
2009年11月 (2)
2009年10月 (1)
2009年9月 (2)
2009年8月 (17)
2009年7月 (9)
2009年6月 (25)
2009年5月 (42)
新聞檔案
2010年2月 (1)
收藏夾
TEST(2)
搜索
最新評論
1.?re: Apache Commons fileUpload實現文件上傳
good
--未來不是夢
2.?re: js操作html的table,包括添加行,添加列,刪除行,刪除列
共和國分隔符
--菊花菊花姐
3.?re: WAP網站可以用Google Analytics統計分析流量
請問ga中對wap站的跟蹤在哪里可以查看,我操作的方式和pc站一樣,都是把網址輸入,就出來一段網址,這樣似乎不對,是嗎,前輩
--ga菜鳥
4.?re: Velocity模板(VM)語言介紹
博主寫的很詳細,學習啦
--winclpt
5.?re: 利用Java編寫簡單的WebService實例[未登錄]
11
--111
閱讀排行榜
1.?Velocity模板(VM)語言介紹(30222)
2.?JSTL對Map集合的操作(21139)
3.?htmlunit 示例(16684)
4.?利用Java編寫簡單的WebService實例(13404)
5.?webservice和soap原理(12105)
評論排行榜
1.?Flex Builder 3 Help 中文版 (CHM/PDF)下載(19)
2.?aptana漢化(3)
3.?WAP網站可以用Google Analytics統計分析流量(2)
4.?Android中添加Admob廣告(轉(2)
5.?axis2 java.lang.reflect.InvocationTargetException (2)
flex3+struts 1.3+spring +ibatis 2.x 整合實例---讓新人少走彎路(myeclipse)
經過兩天工作閑余時間的奮戰,終于flex3+struts 1.3+spring +ibatis 2.x 整合成功,下面介紹下詳細的步驟和核心代碼:
IDE:myeclipse
(當然:前提是FLEX+java整合成功的情況下,關于flex+java整合的文章就比較多,google下就OK):
1.成功整合FLEX+JAVA后,右鍵單擊項目選擇 MyEclipse---》add struts(添加STRUTS比較簡單這里就不多說了),下面貼代碼:
(1)
<?
xml version
=
"
1.0
"
encoding
=
"
UTF-8
"
?>
<!
DOCTYPE struts
-
config PUBLIC
"
-//Apache Software Foundation//DTD Struts Configuration 1.3//EN
"
"
http://struts.apache.org/dtds/struts-config_1_3.dtd
"
>
<
struts
-
config
>
<
form
-
beans
/>
<
global
-
exceptions
/>
<
action
-
mappings
>
<
action
path
=
"
/user
"
type
=
"
com.yinhai.struts.action.UserAction
"
scope
=
"
request
"
>
<
forward name
=
"
sucess
"
path
=
"
/index.jsp
"
/>
</
action
>
</
action
-
mappings
>
</
struts
-
config
>
在web-info下的struts-config.xml中添加如上代碼
(2)UserAction
1
package
com.yinhai.struts.action;
2
3
import
java.io.IOException;
4
import
java.io.PrintWriter;
5
import
java.sql.Connection;
6
import
java.sql.DriverManager;
7
import
java.sql.SQLException;
8
import
java.util.List;
9
10
import
javax.servlet.http.HttpServletRequest;
11
import
javax.servlet.http.HttpServletResponse;
12
13
import
model.User;
14
15
import
org.apache.struts.action.Action;
16
import
org.apache.struts.action.ActionForm;
17
import
org.apache.struts.action.ActionForward;
18
import
org.apache.struts.action.ActionMapping;
19
import
org.springframework.beans.factory.BeanFactory;
20
import
org.springframework.context.support.ClassPathXmlApplicationContext;
21
22
import
dao.ContextHelper;
23
import
dao.UserDaoImpl;
24
25
/** */
/**
26
* MyEclipse Struts
27
* Creation date: 08-05-2009
28
*
29
* XDoclet definition:
30
* @struts.action parameter="method" validate="true"
31
* @struts.action-forward name="fail" path="/fail.jsp"
32
* @struts.action-forward name="sucess" path="/sucess.jsp"
33
*/
34
public
class
UserAction
extends
Action
{
35
/**/
/*
36
* Generated Methods
37
*/
38
39
/** */
/**
40
* Method execute
41
*
@param
mapping
42
*
@param
form
43
*
@param
request
44
*
@param
response
45
*
@return
ActionForward
46
*
@throws
IOException
47
*/
48
public
ActionForward execute(ActionMapping mapping, ActionForm form,
49
HttpServletRequest request, HttpServletResponse response)
{
50
//
ClassPathXmlApplicationContext ctxss = new ClassPathXmlApplicationContext("applicationContext.xml");
51
//
BeanFactory ctx=(BeanFactory)ctxss;
52
//
UserDaoImpl um = (UserDaoImpl) ctx.getBean("userDao");
53
UserDaoImpl um
=
(UserDaoImpl)ContextHelper.getContext().getBean(
"
userDao
"
);
54
List users
=
um.getUsers();
55
User user
=
null
;
56
String xml
=
"
<?xml version=\
"
1.0
\
"
encoding=\
"
utf
-
8
\
"
?><users>
"
;
57
for
(
int
i
=
0
;i
<
users.size();i
++
)
{
58
user
=
(User)users.get(i);
59
xml
=
xml
+
"
<user>
"
+
60
"
<usernumber>
"
+
user.getUsernumber()
+
"
</usernumber>
"
+
61
"
<name>
"
+
user.getName()
+
"
</name>
"
+
62
"
<password>
"
+
user.getPassword()
+
"
</password>
"
+
63
"
</user>
"
;
64
}
65
xml
=
xml
+
"
</users>
"
;
66
System.out.println(xml);
67
PrintWriter p
=
null
;
68
try
{
69
//
p=response.getWriter();
70
response.getWriter().write(xml);
71
72
}
catch
(Exception e)
{
73
//
TODO Auto-generated catch block
74
e.printStackTrace();
75
}
76
//
p.write(xml);
77
//
p.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><users><user><usernumber>1</usernumber><name>caicai</name><password>dddddd</password></user><user><usernumber>2</usernumber><name>yingying</name><password>dddddd</password></user><user><usernumber>3</usernumber><name>ceshi</name><password>dddddd</password></user><user><usernumber>4</usernumber><name>ceshi</name><password>dddddd</password></user>");
78
//
p.close();
79
80
return
null
;
(3)獲取bean的工具類
package
dao;
import
org.springframework.context.support.ClassPathXmlApplicationContext;
/** */
/**
* Date: 2008-3-20 Time: 17:28:48 To change this template use File | Settings |
* File Templates.
*/
public
class
ContextHelper
{
private
static
ClassPathXmlApplicationContext _ctx;
static
{
_ctx
=
new
ClassPathXmlApplicationContext(
"
/applicationContext.xml
"
);
}
public
static
ClassPathXmlApplicationContext getContext()
{
return
_ctx;
}
}
2.添加SRPING
右鍵單擊項目選擇 MyEclipse---》add spring
spring的配置文件
<?
xml version
=
"
1.0
"
encoding
=
"
UTF-8
"
?>
<
beans
xmlns
=
"
http://www.springframework.org/schema/beans
"
xmlns:xsi
=
"
http://www.w3.org/2001/XMLSchema-instance
"
xsi:schemaLocation
=
"
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
"
>
<
bean id
=
"
dataSource
"
class
=
"
org.apache.commons.dbcp.BasicDataSource
"
destroy
-
method
=
"
close
"
>
<
property name
=
"
driverClassName
"
value
=
"
com.mysql.jdbc.Driver
"
/>
<
property name
=
"
url
"
value
=
"
jdbc:mysql://localhost:3306/test
"
/>
<
property name
=
"
username
"
value
=
"
root
"
/>
<
property name
=
"
password
"
value
=
"
root
"
/>
</
bean
>
<
bean id
=
"
sqlMapClient
"
class
=
"
org.springframework.orm.ibatis.SqlMapClientFactoryBean
"
>
<
property name
=
"
configLocation
"
value
=
"
sqlmap-config.xml
"
/>
<
property name
=
"
dataSource
"
ref
=
"
dataSource
"
/>
</
bean
>
<
bean id
=
"
userDao
"
class
=
"
dao.UserDaoImpl
"
>
<
property name
=
"
sqlMapClient
"
ref
=
"
sqlMapClient
"
/>
</
bean
>
</
beans
>
(3)添加IBATIS
首先將ibatis的JAR包導入,放在LIB下即可
IBTIS配置文件
sqlmapconfig.xml
<?
xml version
=
"
1.0
"
encoding
=
"
UTF-8
"
?>
<!
DOCTYPE sqlMapConfig
PUBLIC
"
-//ibatis.apache.org//DTD SQL Map Config 2.0//EN
"
"
http://ibatis.apache.org/dtd/sql-map-config-2.dtd
"
>
<
sqlMapConfig
>
<!--
Configure a built
-
in transaction manager. If you
'
re using an
app server, you probably want to use its transaction manager
and a managed datasource
-->
<!--
List the SQL Map XML files. They can be loaded from the
classpath, as they are here (com.domain.data
)
-->
<
sqlMap resource
=
"
dao/User.xml
"
/>
<!--
List more here
<
sqlMap resource
=
"
com/mydomain/data/Order.xml
"
/>
<
sqlMap resource
=
"
com/mydomain/data/Documents.xml
"
/>
-->
</
sqlMapConfig
>
User.xml
<?
xml version
=
"
1.0
"
encoding
=
"
UTF-8
"
?>
<!
DOCTYPE sqlMap
PUBLIC
"
-//ibatis.apache.org//DTD SQL Map 2.0//EN
"
"
http://ibatis.apache.org/dtd/sql-map-2.dtd
"
>
<
sqlMap namespace
=
"
User
"
>
<!--
Use type aliases to avoid typing the full classname every time.
-->
<
typeAlias alias
=
"
user
"
type
=
"
model.User
"
/>
<!--
Select with no parameters using the result map
for
Account
class
.
-->
<
select id
=
"
getUsers
"
resultClass
=
"
user
"
>
select
*
from user;
</
select
>
</
sqlMap
>
注意:User.xml一定要和相應的DAO的實現類放一個包下
4.FLEX文件
<?
xml version
=
"
1.0
"
encoding
=
"
utf-8
"
?>
<
mx:Application xmlns:mx
=
"
http://www.adobe.com/2006/mxml
"
layout
=
"
absolute
"
>
<
mx:Script
>
<!
[CDATA[
import
mx.rpc.events.FaultEvent;
import
mx.controls.Alert;
import
mx.rpc.events.ResultEvent;
import
mx.controls.DataGrid;
[Bindable]
public
var gridXml:XML;
public
function httpHandler(event:ResultEvent):
void
{
Alert.show(
"
hello2
"
);
gridXml
=
XML(event.result);
griddata.dataProvider
=
gridXml.children();
//
XMLList
}
public
function initHandler():
void
{
testHttp.url
=
"
http://localhost:8080/LCSYS/user.do
"
;
Alert.show(
"
hello1
"
);
testHttp.send();
}
public
function httpFail(event:FaultEvent):
void
{
Alert.show(
"
調用失敗
"
);
Alert.show(event.message.toString());
}
]]
>
</
mx:Script
>
<
mx:HTTPService id
=
"
testHttp
"
result
=
"
httpHandler(event)
"
fault
=
"
httpFail(event)
"
resultFormat
=
"
e4x
"
/>
<
mx:Panel x
=
"
171
"
y
=
"
64
"
width
=
"
670
"
height
=
"
342
"
layout
=
"
absolute
"
id
=
"
userPannel
"
title
=
"
userPannel1
"
>
<
mx:DataGrid x
=
"
0
"
y
=
"
0
"
width
=
"
100%
"
height
=
"
100%
"
id
=
"
griddata
"
>
<
mx:columns
>
<
mx:DataGridColumn dataField
=
"
usernumber
"
headerText
=
"
usernumber
"
/>
<
mx:DataGridColumn dataField
=
"
name
"
headerText
=
"
name
"
/>
<
mx:DataGridColumn dataField
=
"
password
"
headerText
=
"
password
"
/>
</
mx:columns
>
</
mx:DataGrid
>
<
mx:ControlBar height
=
"
34
"
y
=
"
262
"
>
<
mx:Button label
=
"
查詢人員列表
"
click
=
"
initHandler()
"
/>
</
mx:ControlBar
>
</
mx:Panel
>
</
mx:Application
>
5.其他文件:
工具類,解決亂碼
package
dao;
import
java.io.UnsupportedEncodingException;
import
org.springframework.context.support.ClassPathXmlApplicationContext;
public
class
Tool
{
public
static
String change(String str)
{
String str2;
try
{
str2
=
new
String(str.getBytes(
"
iso-8859-1
"
),
"
UTF-8
"
);
return
str2;
}
catch
(UnsupportedEncodingException e)
{
//
TODO Auto-generated catch block
e.printStackTrace();
}
return
null
;
}
}
userDaoImpl
package
dao;
import
java.util.List;
import
org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
public
class
UserDaoImpl
extends
SqlMapClientDaoSupport
implements
UserDao
{
public
List getUsers()
{
//
TODO Auto-generated method stub
return
this
.getSqlMapClientTemplate().queryForList(
"
getUsers
"
);
}
}
時間關系,介紹得比較粗糙也沒撒說明,不過只要對框架較熟悉的應該很快能搭建起環境
本文章主要是集成框架介紹
注意:需要IBATIS的JAR吧,dbcp連接池的包,還有相應的驅動包
posted on 2009-08-13 14:38
小菜毛毛
閱讀(2714)
評論(4)
編輯
收藏
所屬分類:
J2EE相關技術與框架
Feedback
#
re: flex3+struts 1.3+spring +ibatis 2.x 整合實例---讓新人少走彎路(myeclipse)[未登錄]
2011-07-07 11:26
aaa
都不說明一下,直接發一堆代碼,寫了跟沒寫有什么區別,新人能看懂嗎
回復
更多評論
#
re: flex3+struts 1.3+spring +ibatis 2.x 整合實例---讓新人少走彎路(myeclipse)
2012-11-16 15:27
王志國
挺好的
回復
更多評論
#
re: flex3+struts 1.3+spring +ibatis 2.x 整合實例---讓新人少走彎路(myeclipse)
2012-11-16 15:28
王志國
原來都是錯誤,這次到反映點東西回來。
將struts中Action后的jsp網頁給傳回來了。神奇!
回復
更多評論
#
re: flex3+struts 1.3+spring +ibatis 2.x 整合實例---讓新人少走彎路(myeclipse)
2014-04-13 21:33
最代碼
最代碼上轉載了你的文章,有問題請回復,地址:
http://www.zuidaima.com/share/1778657261997056.htm
回復
更多評論
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
web.xml配置屬性獲取
jxl的API
JDBC,連接池 代碼模擬
Apache Commons fileUpload實現文件上傳
Apache Commons工具集簡介
純jsp的單個文件上載代碼
Java中文問題及最優解決方法
文件上傳原理簡單實現
在jsp/servlet中斷點/多線程下載文件
response.setContentType 的參數說明
Copyright @ 小菜毛毛
Powered by:
.Text
and
ASP.NET
Theme by:
.NET Monster
主站蜘蛛池模板:
亚洲欧美日韩中文字幕一区二区三区
|
伊人久久综在合线亚洲91
|
亚洲日韩国产成网在线观看
|
亚洲日韩精品一区二区三区无码
|
久久精品亚洲中文字幕无码网站
|
亚洲精品成人图区
|
亚洲jizzjizz少妇
|
一道本不卡免费视频
|
免费黄色电影在线观看
|
亚洲综合日韩中文字幕v在线
|
亚洲免费观看在线视频
|
亚洲av午夜国产精品无码中文字
|
亚洲综合偷自成人网第页色
|
国产精品亚洲а∨无码播放不卡
|
中文字幕a∨在线乱码免费看
|
精品免费久久久久久久
|
国产大片91精品免费观看男同
|
国产亚洲欧洲Aⅴ综合一区
|
亚洲白色白色在线播放
|
色噜噜的亚洲男人的天堂
|
大地资源中文在线观看免费版
|
亚洲第一成年免费网站
|
亚洲七七久久精品中文国产
|
亚洲自偷精品视频自拍
|
免费在线观看亚洲
|
免费国产污网站在线观看15
|
国产片免费在线观看
|
亚洲AV无码成人专区片在线观看
|
亚洲中文字幕久久精品无码A
|
成人免费无码H在线观看不卡
|
妻子5免费完整高清电视
|
中文字幕第一页亚洲
|
亚洲乱码无限2021芒果
|
eeuss草民免费
|
好大好深好猛好爽视频免费
|
国产精品xxxx国产喷水亚洲国产精品无码久久一区
|
三上悠亚电影全集免费
|
国产精品免费观看久久
|
在线成人a毛片免费播放
|
亚洲va国产va天堂va久久
|
亚洲AV第一成肉网
|