用XML结合数据库,给服务器减负(3)
作者:殷亮 时间:2007-10-31 09:40:00
我们的思路是:
1.客户端向服务器的某个ASP程序发出查询条件。
2.该ASP程序响应,并连接数据库。
3.数据库将查询结果返回给该ASP程序。
4.获得数据后,用ASP程序将数据格式化为XML格式, 从而将查询结果建立为该ASP的内嵌式XML对象。
5.在客户端实现XML的分页(分页方法类似于数据库分页)
6.此后,无论是客户端将查询结果翻多少页看多少遍,均不会再与服务器发生交互。
另外,就算是客户端断开网线,也仍然可以浏览还未浏览的分页页面。
下面是我写的一个歌曲在线播放程序页面程序,由两个文件构成:
songList.mdb 一个数据库,装载着歌曲信息。songList.asp ASP程序,数据库中的数据格式成XML,页面完全显示后,无论点多少次“下一首”,也不会与服务器交互。
◆songList.asp◆
<html>
<head>
<title>殷亮的在线播放</title>
<style type="text/CSS">
<!--
.input
{
background-color: #000000;
border: #000000;
color: #FF9900;
}
-->
</style>
</head>
<body bgcolor="#000000" text="#FF9900">
<% ''''''''''''''''''''连接数据库'''''''''''''''''''''''''
set songCon = Server.CreateObject("ADODB.connection")
conPath = Server.MapPath("songList.mdb")
conStr = "DRIVER={Microsoft Access Driver (*.mdb)}; dbq="
songCon.open(conStr & conPath)
set rs = Server.CreateObject("ADODB.Recordset")
rs.open "Select * from songList",songCon,3,3
%>
<!--动态生成内嵌式XML文档,"在线播放"是根标记-->
<xml id = "xmlFile">
<在线播放>
<%
If not rs.eof then
while not rs.eof
%>
<歌曲>
<歌名><%= trim(rs("song_name")) %></歌名>
<URL><%= trim(rs("song_url")) %></URL>
<演唱者><%= trim(rs("songer")) %></演唱者>
<歌词><%= trim(rs("song_lyrics")) %></歌词>
</歌曲>
<%
rs.movenext
wend
End If
%>
</在线播放>
</xml>
<div id="Layer1" style="position:absolute; width:500px; height:59px; z-index:1; left: 118px; top: 4px;">
<!--Window Media Player控件-->
<OBJECT classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" width="500" height="43" id="player" style="WIDTH: 500px; HEIGHT: 43px" VIEWASTEXT>
<PARAM NAME="AudioStream" VALUE="-1">
<PARAM NAME="AutoSize" VALUE="0">
<PARAM NAME="AutoStart" VALUE="-1">
<PARAM NAME="AnimationAtStart" VALUE="-1">
<PARAM NAME="AllowScan" VALUE="-1">
<PARAM NAME="AllowChangeDisplaySize" VALUE="-1">
<PARAM NAME="AutoRewind" VALUE="0">
<PARAM NAME="Balance" VALUE="0">
<PARAM NAME="BaseURL" VALUE="">
<PARAM NAME="BufferingTime" VALUE="5">
<PARAM NAME="CaptioningID" VALUE="">
<PARAM NAME="ClickToPlay" VALUE="-1">
<PARAM NAME="CursorType" VALUE="0">
<PARAM NAME="CurrentPosition" VALUE="-1">
<PARAM NAME="CurrentMarker" VALUE="0">
<PARAM NAME="DefaultFrame" VALUE="">
<PARAM NAME="DisplayBackColor" VALUE="0">
<PARAM NAME="DisplayForeColor" VALUE="16777215">
<PARAM NAME="DisplayMode" VALUE="0">
<PARAM NAME="DisplaySize" VALUE="4">
<PARAM NAME="Enabled" VALUE="-1">
<PARAM NAME="EnableContextMenu" VALUE="-1">
<PARAM NAME="EnablePositionControls" VALUE="-1">
<PARAM NAME="EnableFullScreenControls" VALUE="0">
<PARAM NAME="EnableTracker" VALUE="-1">
<PARAM NAME="Filename" VALUE="">
<PARAM NAME="InvokeURLs" VALUE="-1">
<PARAM NAME="Language" VALUE="-1">
<PARAM NAME="Mute" VALUE="0">
<PARAM NAME="PlayCount" VALUE="1">
<PARAM NAME="PreviewMode" VALUE="0">
<PARAM NAME="Rate" VALUE="1">
<PARAM NAME="SAMILang" VALUE="">
<PARAM NAME="SAMIStyle" VALUE="">
<PARAM NAME="SAMIFileName" VALUE="">
<PARAM NAME="SelectionStart" VALUE="-1">
<PARAM NAME="SelectionEnd" VALUE="-1">
<PARAM NAME="SendOpenStateChangeEvents" VALUE="-1">
<PARAM NAME="SendWarningEvents" VALUE="-1">
<PARAM NAME="SendErrorEvents" VALUE="-1">
<PARAM NAME="SendKeyboardEvents" VALUE="0">
<PARAM NAME="SendMouseClickEvents" VALUE="0">
<PARAM NAME="SendMouseMoveEvents" VALUE="0">
<PARAM NAME="SendPlayStateChangeEvents" VALUE="-1">
<PARAM NAME="ShowCaptioning" VALUE="0">
<PARAM NAME="ShowControls" VALUE="-1">
<PARAM NAME="ShowAudioControls" VALUE="-1">
<PARAM NAME="ShowDisplay" VALUE="0">
<PARAM NAME="ShowGotoBar" VALUE="0">
<PARAM NAME="ShowPositionControls" VALUE="-1">
<PARAM NAME="ShowStatusBar" VALUE="0">
<PARAM NAME="ShowTracker" VALUE="-1">
<PARAM NAME="TransparentAtStart" VALUE="0">
<PARAM NAME="VideoBorderWidth" VALUE="0">
<PARAM NAME="VideoBorderColor" VALUE="0">
<PARAM NAME="VideoBorder3D" VALUE="0">
<PARAM NAME="Volume" VALUE="0">
<PARAM NAME="WindowlessVideo" VALUE="0">
</OBJECT>
</div>
<div id="Layer3" style="position:absolute; width:200px; height:115px; z-index:3; left: 120px; top: 140px;"><img src="P_online.jpg" width="300" height="170"></div>
<div id="Layer4" style="position:absolute; width:191px; height:54px; z-index:4; left: 430px; top: 199px;">
<table width="190" height="52" border="1" align="right" bordercolor="#000000" bgcolor="#FF9900">
<tr>
<td height="23" valign="bottom">
<div align="center"></div>
<div align="right">
<input name="btnPre" type="button" disabled="true" id="btnPre" value="上一首">
</div></td>
</tr>
<tr>
<td valign="top">
<div align="right">
<input name="btnNext" type="button" id="btnNext" value="下一首">
</div></td>
</tr>
</table>
</div>
<div id="Layer2" style="position:absolute; width:503px; height:58px; z-index:2; left: 120px; top: 67px;">
<table width="501" border="1">
<tr>
<td width="100"><font color="#FFFFFF" size="2">播放内置歌曲:</font></td>
<td width="317">
<SELECT name="list" size="1" id="list" style="WIDTH: 328px; BACKGROUND-COLOR: darkorange">
<!--用循环来初始化下拉列表-->
<script language="VBScript">
set xml=xmlFile.recordset
xml.MoveFirst
dim num
for num=0 to xml.RecordCount-1
document.write("<OPTION value="&xml("url")&">"&xml("歌名")&"</OPTION>")
xml.MoveNext
next
xml.MoveFirst
</script>
</SELECT>
</td>
<td width="62"><div align="right">
<input name="btnLAN" type="button" id="btnLAN" value="播放">
</div></td>
</tr>
<tr>
<td><font color="#FFFFFF" size="2" >播放网络歌曲:</font></td>
<td><input name="textURL" type="text" id="textURL" style="WIDTH: 328px; BACKGROUND-COLOR: darkorange;color: #000000;"></td>
<td><div align="right">
<input name="btnNET" type="reset" id="btnNET" value="播放">
</div></td>
</tr>
</table>
</div>
<div id="Layer5" style="position:absolute; width:500px; height:20px; z-index:5; left: 120px; top: 320px;">
<p><font color="#FFFFFF" size="2">正在播放:
<input name="textSonger" type="text" class="input" id="textSonger" size="15">
演唱的
<input name="textSongName" type="text" class="input" id="textSongName" size="35">
</font></p>
</div>
<div id="Layer6" style="position:absolute; width:500px; height:150px;
z-index:6; left: 120px; top: 349px;">
<textarea name="area" cols="68" rows="15" id="area"
style="BORDER-RIGHT: white double; BORDER-TOP: white double;
BORDER-LEFT: white double;COLOR: #000000; DIRECTION: ltr;
BORDER-BOTTOM: white double;BACKGROUND-COLOR: darkorange;
TEXT-ALIGN: left">
</textarea>
</div>
<!--各按钮的单击事件-->
<script language="VBScript">
sub play()
textSonger.value=xml("演唱者")
textSongName.value=xml("歌名")
textURL.value=""
area.value=xml("歌词")
player.filename=xml("URL")
if xml.AbsolutePosition=xml.recordcount then
btnNext.disabled=true
else
btnNext.disabled=false
end if
if xml.AbsolutePosition=1 then
btnPre.disabled=true
else
btnPre.disabled=false
end if
end sub
sub btnLAN_onclick
xml.MoveFirst
while xml("URL")<>list.value
xml.MoveNext
wend
call play()
end sub
sub btnNET_onclick
player.filename = textURL.value
textSonger.value = ""
textSongName.value = ""
area.value = "自定义网络歌曲"
end sub
sub btnPre_onclick
xml.MovePrevious
list.selectedIndex = list.selectedIndex - 1
call play()
end sub
sub btnNext_onclick
xml.MoveNext
list.selectedIndex = list.selectedIndex + 1
call play()
end sub
</script>
</body>
</html>
现在,你知道怎么给服务器减负了吗?^-^本文旨在探讨,如有错漏,欢迎指正与讨论。
感谢站长miles这些日子来不倦的帮助,无以回报,唯有灌上此文。
标签:xml,数据库,asp,服务器
0
投稿
猜你喜欢
python Graham求凸包问题并画图操作
2023-06-01 12:37:00
解决Python安装时报缺少DLL问题【两种解决方法】
2023-12-27 01:49:12
Django model序列化为json的方法示例
2022-08-25 01:39:03
Django QuerySet查询集原理及代码实例
2023-04-06 01:30:18
SQL server分页的4种方法示例(很全面)
2024-01-27 15:09:47
如何用ASP实现文章点击数?
2008-08-11 21:17:00
Python中你所不知道的星号 * 用法
2022-08-06 15:25:43
Tornado路由与Application的实现
2021-01-26 19:56:59
Python实现基于PIL和tesseract的验证码识别功能示例
2022-10-22 23:09:54
Python中的异常处理讲解
2023-01-29 11:22:57
SQL Server正则表达式 替换函数应用详解
2023-07-07 23:53:13
Python数据拟合实现最小二乘法示例解析
2023-12-17 05:46:36
python 提取html文本的方法
2021-05-27 03:43:46
如何基于python实现不邻接植花
2023-10-14 16:35:45
Python爬虫新手入门之初学lxml库
2021-11-19 07:16:29
在Pycharm terminal中字体大小设置的方法
2023-11-12 07:12:56
Python实现线程状态监测简单示例
2023-12-07 20:31:25
JavaScript在ASP页面中实现掩码文本框效果代码
2013-06-01 19:57:23
python中使用ctypes调用so传参设置遇到的问题及解决方法
2021-06-02 00:38:39
编写PHP脚本使WordPress的主题支持Widget侧边栏
2023-11-23 20:27:13