中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > Web开发 > XML
用XML结合数据库,给服务器减负二
作者:yestar2000 时间:2001-12-23 11:46 出处:互联网 责编:chinaitpower
              摘要:用XML结合数据库,给服务器减负二

  我们的思路是:

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这些日子来不倦的帮助,无以回报,唯有灌上此文

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有