數據庫表
這個sql是用
pd
生成的,具體內容大家自己看一下好了,很簡單,數據也自己填充一下。標題上說是用
mysql
<clk>,其實無所謂用啥數據庫了,這里我<nobr id="clickeyekey0" style="border-bottom: 1px dotted rgb(102, 0, 255); text-decoration: underline; color: rgb(102, 0, 255); background-color: transparent;" onclick="kwC(event,0)" oncontextmenu="return false" onmouseover="kwE(event,0, this)" onmouseout="kwL(event,this)" onmousemove="kwM(0)">推薦</nobr></clk>
Postgresql
,現在有for win平臺了,不用
cygwin
來模擬unix環境,這個
Postgresql
一來小巧,二來功能齊全,看起來有點象
Oracle
,當然速度也很快了。
/* Table:tblmobile */
/* ============================================================== */
create table tblmobile
(
id integer ( 11 ) not null default 0 ,
categoryid integer ( 11 ),
name varchar ( 255 ),
image varchar ( 255 ),
price decimal ( 12 , 2 ),
addtime datetime ,
primary key (id)
);
/* ============================================================== */
/* Index:i_tblMobile_categoryid */
/* ============================================================== */
create index i_tblMobile_categoryid on tblmobile
(
categoryid
);
/* ============================================================== */
/* Index:pk_tblmobile */
/* ============================================================== */
create unique index pk_tblmobile on tblmobile
(
id
);
/* ============================================================== */
/* Index:i_tblmobile_addtime */
/* ============================================================== */
create index i_tblmobile_addtime on tblmobile
(
addtime
);
phonselist.jsp
Jsp服務器用的是 Tomcat ,順便做 flex <clk>的服務器,版本沒啥大關系,我現在用的是5.0.28,Jsp功能是按<nobr id="clickeyekey2" style="border-bottom: 1px dotted rgb(102, 0, 255); text-decoration: underline; color: rgb(102, 0, 255); background-color: transparent;" onclick="kwC(event,2)" oncontextmenu="return false" onmouseover="kwE(event,2, this)" onmouseout="kwL(event,this)" onmousemove="kwM(2)">手機</nobr>分類id從</clk> mysql 數據庫獲取手機列表,這里為方便起見直接在jsp頁面里進行數據庫訪問,正確的做法應該由 javabean 來分工,其后總jsp生成的是一個xml文件。
< %@pagecontentType = " text/html;charset=utf-8 " % >
< %@pageimport = " java.sql.* " % >
< phonelist >
< %
String sql = "" ;
String url = "" ;
String categoryID = request.getParameter( " categoryID " );
try {
Class .forName( " com.mysql.jdbc.Driver " ).newInstance();
url = " jdbc:mysql://localhost/web?user=flex&password=flex&useUnicode=true&characterEncoding=gb2312 " ;
Connectionconn = DriverManager.getConnection(url);
Statementstmt = conn.createStatement();
sql = " selectid,name,price,imagefromtblMobilewherecategoryid= " + categoryID;
ResultSetrs = stmt.executeQuery(sql);
while (rs. next ()){
out.println( " <phoneid=/""+rs.getString(1)+ " / " > " );
out.println( " <id> " + rs.getString( 1 ) + " </id> " );
out.println( " <name> " + rs.getString( 2 ) + " </name> " );
out.println( " <price> " + rs.getString( 3 ) + " </price> " );
out.println( " <image> " + rs.getString( 4 ) + " </image> " );
out.println( " </phone> " );
}
rs.close();
stmt.close();
conn.close();
} catch (Exceptione){
out.println(e);
}
% >
</ phonelist >
mobile.mxml
這里要注意一下 <mx:HTTPService> 中的 resultFormat="xml" 的設置,在這里應該把這個取掉(我原來是用來做Tree用的)。phonelisg.jsp和mobile.mxml放在相同的目錄下,當然你也可以修改 url 的路徑。
< mx:Application xmlns:mx ="http://www.macromedia.com/2003/mxml"
verticalGap ="10"
backgroundColor ="#FFFFFF"
pageTitle ="手機"
initialize ="initApp()" >
< mx:Style source ="main.css" />
< mx:HTTPService id ="phoneService" url ="phonelist.jsp" resultFormat ="xml" >
< mx:request >
< categoryID > {categoryId} </ categoryID >
</ mx:request >
</ mx:HTTPService >
< mx:Model id ="phonelist" >
{phoneService.result.phonelist.phone}
</ mx:Model >
< mx:Script >
<![CDATA[
varcategoryId=2;
varcategoryName="Moto";
functioninitApp(){
phoneService.send();
}
]]>
</ mx:Script >
< mx:HBox >
< mx:LinkBar styleName ="title" width ="500" click ="" >
< mx:dataProvider >
< mx:Array >
< mx:Object label ="首頁" link ="main" />
< mx:Object label ="手機分類" link ="catagory" />
< mx:Object label ="論壇" link ="forum" />
< mx:Object label ="關于" link ="about" />
</ mx:Array >
</ mx:dataProvider >
</ mx:LinkBar >
< mx:Label text ="搜索" />
< mx:TextInput id ="key" width ="120" />
< mx:Button label ="Go" />
</ mx:HBox >
< mx:HBox >
< mx:Image source ="images/qd_2.jpg" />
< mx:Label id ="debug" text ="123" />
</ mx:HBox >
< mx:Effect >
< mx:Zoom name ="zoomBig" zoomTo ="107" duration ="100" />
< mx:Zoom name ="zoomSmall" zoomTo ="100" duration ="100" />
</ mx:Effect >
< mx:HBox >
< mx:Panel id ="main" title ="" height ="360" >
< mx:Tile width ="520" >
< mx:Repeater id ="plist" dataProvider ="{phonelist}" startingIndex ="" count ="" >
< mx:VBox id ="itemBox" verticalGap ="0" horizontalAlign ="center" mouseUp ="" >
< mx:Canvas width ="100" height ="100" clipContent ="false" >
< mx:Image width ="90" height ="90" source ="{plist.currentItem.image}" toolTip ="RMB{plist.currentItem.price}" mouseOverEffect ="zoomBig" mouseOutEffect ="zoomSmall" visible ="false" complete ="event.target.visible=true;" />
</ mx:Canvas >
< mx:Label id ="itemName" text ="{plist.currentItem.name}" />
< mx:Label id ="itemPrice" text ="RMB{plist.currentItem.price}" />
</ mx:VBox >
</ mx:Repeater >
</ mx:Tile >
< mx:ControlBar >
< mx:Button label ="上一頁" click ="" />
< mx:Button label ="下一頁" click ="" />
< mx:Button label ="refresh" click ="initApp()" />
</ mx:ControlBar >
</ mx:Panel >
</ mx:HBox >
< mx:HBox horizontalAlign ="center" >
< mx:Label text ="CopyRight2004dannyr'sStudio" />
</ mx:HBox >
</ mx:Application >
最后:配置Flex服務器
flex
-config.xml
< whitelist >
< unnamed >
< url > http://{localserver}/flex/phonelist.jsp </ url >
</ unnamed >
</ whitelist >
</ http-service-proxy >
【本文轉自網絡無名氏】
另附幾篇文章:
Flex與Servlet通訊
RIA技術入門之Macromedia Flex & JSP(一)
RIA技術入門之Macromedia Flex & JSP(二)
RIA技術入門之Macromedia Flex & JSP(三)
RIA技術入門之Macromedia Flex & JSP(四)
簡單的flex 2 mysql jsp實例
<!-- Google Reader shared發布代碼開始 --> <script type="text/javascript" src="http://www.google.com/reader/ui/publisher.js"></script><script type="text/javascript" src="http://www.google.com/reader/public/javascript/user/00697638153916680411/state/com.google/broadcast?n=5&callback=GRC_p%28%7Bc%3A%22green%22%2Ct%3A%22%5Cu8FD9%5Cu4E9B%5Cu6587%5Cu7AE0%5Cu4E5F%5Cu503C%5Cu5F97%5Cu4E00%5Cu770B%22%2Cs%3A%22false%22%7D%29%3Bnew%20GRC"></script><!-- Google Reader shared發布代碼結束 -->
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
