ITeye博客

flex与asp,access的联系(1)

bluefox · 2007-08-24 16:26 · flash&flex · 企业架构 · Markdown

首先,我们在ACCESS里面建好数据库,字段分别是id,title,ptime,msg,link.然后在数据库里面添加一些内容.把数据库建好之后,应该写个ASP文件去把数据库中的内容读取出来,并以XML的格式显示出来.然后就可以利用FLEX的HTTPService组件去读取XML的值,总的思路是这样的,以下为代码,具体介绍就没有了,留给读者慢慢体会. conn.asp

<% Dim Fy_Post,Fy_Get,Fy_In,Fy_Inf,Fy_Xh,Fy_db,Fy_dbstr '自定义需要过滤的字串,用 "|" 分隔 Fy_In = "'|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare|user" '---------------------------------- %>

<% Fy_Inf = split(Fy_In,"|") '--------POST部份------------------ If Request.Form<>"" Then For Each Fy_Post In Request.Form

For Fy_Xh=0 To Ubound(Fy_Inf) If Instr(LCase(Request.Form(Fy_Post)),"request")<>0 Then

Response.Write "Please do not submit illegal parameters " Response.End End If Next

Next End If '----------------------------------

'--------GET部份------------------- If Request.QueryString<>"" Then For Each Fy_Get In Request.QueryString

For Fy_Xh=0 To Ubound(Fy_Inf) If Instr(LCase(Request.QueryString(Fy_Get)),Fy_Inf(Fy_Xh))<>0 Then

Response.Write "Please do not submit illegal parameters " Response.End End If Next Next End If '---------------------------------- %> <% function getdata(sql,rs,conn) set conn=server.createobject("adodb.connection") db="book.mdb" conn.open "provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.mappath(db) set rs=server.createobject("adodb.recordset") rs.open sql,conn,3,2 end function

function closedb(rs,conn) rs.close set rs=nothing conn.close set conn=nothing end function %> 然后就是建一个ASP文件去把数据库的内容读取并以XML形式显示. name2.asp

<% response.ContentType="text/xml"

dim sql1,rs1,conn1

sql1="select * from book" getdata sql1,rs1,conn1

response.Write("")

do while not rs1.eof

response.write("")

response.write(""&rs1("id")&"")

response.write(""&rs1("title")&"") response.write(""&rs1("ptime")&"") response.write(""&rs1("msg")&"") response.write(""&rs1("link")&"") response.write("") rs1.movenext() loop closedb rs1,conn1 response.write("") %> 在IIS服务器下面测试通过之后,接着写一个MXML文件,去读取ASP得出的值. name2.mxml 文件

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete = "feedRequest.send()"> <mx:HTTPService id="feedRequest" url="http://localhost/paragon/name2.asp" useProxy="false" contentType="application/xml" method="get" /> <mx:Panel x="10" y="10" width="475" height="400" layout="absolute"> <mx:DataGrid x="20" y="20" id="dgPosts" width="400"
dataProvider="{feedRequest.lastResult.news.item}"> mx:columns <mx:DataGridColumn headerText="Column 1" dataField="title"/> <mx:DataGridColumn headerText="Column 2" dataField="ptime"/> <mx:DataGridColumn headerText="Column 2" dataField="msg"/> </mx:columns> </mx:DataGrid> <mx:LinkButton x="20" y="225" label="Read Full Post" click="navigateToURL(new
URLRequest(dgPosts.selectedItem.link))"/> <mx:TextArea x="20" y="175" width="400"/> </mx:Panel> </mx:Application> 注意,我的ASP文件和数据库文件都放在paragon文件下面,然后我把mxml文件放在APACHE TOMCAT的webapps\flex目录下面,一切准备好之后,启动TOMCAT服务器,输入URL:http://localhost:8080/flex/name2.mxml 上面的前提是安装了FDS之后,并完成一些相关配置之后.具体配置可上网查阅.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。