小菜毛毛技術分享
與大家共同成長
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)語言介紹(30220)
2.?JSTL對Map集合的操作(21138)
3.?htmlunit 示例(16683)
4.?利用Java編寫簡單的WebService實例(13403)
5.?webservice和soap原理(12103)
評論排行榜
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
小菜毛毛
閱讀(2713)
評論(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
主站蜘蛛池模板:
四虎影院免费视频
|
成人免费视频网址
|
亚洲国产精品一区二区第四页
|
手机在线看永久av片免费
|
亚洲视频2020
|
亚洲欧美日韩中文字幕在线一区
|
国产久爱免费精品视频
|
8888四色奇米在线观看免费看
|
亚洲av最新在线网址
|
一级毛片在线免费看
|
亚洲Av无码乱码在线znlu
|
国产亚洲视频在线观看网址
|
97无码人妻福利免费公开在线视频
|
在线观看无码的免费网站
|
亚洲av无码有乱码在线观看
|
日韩av无码久久精品免费
|
亚洲视频一区二区在线观看
|
一区二区视频免费观看
|
亚洲无线码一区二区三区
|
国产亚洲精品成人久久网站
|
亚洲另类少妇17p
|
国产精品区免费视频
|
亚洲最大av无码网址
|
亚洲成av人在线观看网站
|
四虎AV永久在线精品免费观看
|
黄色视屏在线免费播放
|
久久亚洲AV成人出白浆无码国产
|
国产亚洲精品免费视频播放
|
亚洲国产人成精品
|
a级黄色毛片免费播放视频
|
亚洲综合无码精品一区二区三区
|
免费看一级高潮毛片
|
久久久亚洲精品蜜桃臀
|
久久午夜夜伦鲁鲁片免费无码影视
|
亚洲午夜久久久影院
|
xxxx日本免费
|
亚洲一区二区三区在线观看网站
|
亚洲AV无码乱码在线观看牲色
|
任你躁在线精品免费
|
亚洲高清中文字幕免费
|
午夜dj免费在线观看
|