flex与asp,access的联系(1)

首先,我们在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

<!--#include file="conn.asp"-->
<%
response.ContentType="text/xml"

dim sql1,rs1,conn1


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

response.Write("<news>")

do while not rs1.eof

response.write("<item>")

response.write("<id>"&rs1("id")&"</id>")

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

<?xml version="1.0" encoding="utf-8"?>
<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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值