- web应用程序设计:ASP.NET/PHP/JSP技术教程
- 林宏基 黄风华 池灵达 林菡
- 1436字
- 2025-02-17 13:18:32
4.5 Content Linking内容链接组件
Content Linking内容链接组件可以便捷地在页面上建立大量的链接。可以在这些页面中建立一个目录表,还可以在它们中间建立动态链接,并自动生成和更新目录表及先前和后续的Web页的导航链接。Content Linking组件提供了管理网页或网址间的超文本链接的功能。它是通过一个“网页或网址的线性排列顺序文件”列表来管理多个网页或网址间的超文本链接顺序。需要建立大量的链接为访问者链接提供导航时,采用这个组件会事半功倍。
要建立一个具有内容超级链接功能的页面至少需要两个文件,一个是用来设定链接内容的txt文件,另一个是建立asp文件,以便调用内容超级链接组件对象的各类方法。
4.5.1 创建Content Linking组件对象
语法格式:Set对象名=Server.CreateObject("MSWC.NextLink")
4.5.2 建立网页或网址URL顺序表文件
网页或网址URL顺序表文件是一个文本文件,其格式如下:
网页的URL["tab"键描述文字(附注文字)]
其中各参数的意义如下。
(1)网页的URL:表示与页面相关的超链接地址,可以是相对路径,也可以是绝对路径。
(2)描述文字:提供了能被超链使用的文本信息,用于对网页或网址的描述,可以是一段文字,也可以用<img>标签对应到一个图形文件。
(3)附注文字:是对特定网页或网址的进一步说明,它的作用如同程序中的注释。
(4)在这两列之间只能用tab键来隔开,否则组件会不能认识。
4.5.3 Content Linking对象方法
以下分别列出了Content Linking对象的8个方法。
(1)GetListCount()方法。
该方法获取组件中包含的链接的“网页URL”数目,用法如下:

(2)GetListIndex()方法。
该方法获取内容链接列表文件中的“网页URL”的索引,用法如下:

(3)GetPreviousURL()方法。
该方法获取内容链接列表文件中所列的前一页“网页URL”,用法如下:

(4)GetPreviousDescription()方法。
该方法获取内容链接列表文件中所列的前一页“网页URL”的说明,用法如下:
字符串=GetPreviousDescription("URL顺序表文件"名)
(5)GetNextURL()方法。
该方法获取内容链接列表文件中所列的下一页“网页URL”,用法如下:

(6)GetNextDescription()方法。
该方法获取内容链接列表文件中所列的下一页“网页URL”的说明,用法如下:

(7)GetNthURL()方法。
该方法获取内容链接列表文件中所列的第N页“网页URL”,用法如下:

(8)GetNthDescription()方法。
该方法获取内容链接列表文件中所列的第N页“网页URL”的说明,用法如下:

【例4.5.1】用Content Linking进行网络导航实例
4-5-1. txt顺序表文件的内容如下:

4-5-1. asp程序代码如下:

4-5-1_1. asp程序代码如下:


4-5-1_2. asp程序代码如下:
<%′4-5-1_2.asp response.write"<h3>——巴巴多斯资料——</h3>"response.write"面积:431平方公里<br>"response.write"人口:28万<br>"response.write"首都:布里奇敦<br>"response.write"语言:英语<br>"%>
4-5-1_3. asp程序代码如下:

4-5-1. asp程序的输入界面如图4.5.1所示。选择列表文本文件中“古巴共和国”项,则链接到如图4.5.2所示页面。

图4.5.1 网络导航实例

图4.5.2 导航后资料
4.5.4 ASP的包含文件
ASP的包含文件是指使用SSI指令在Web服务器处理之前将一个文件的内容插入到另一个文件的方法。

“文件名”包含文件的路径和名称。被包含文件不要求专门的文件扩展名,可以是html、asp、ini和txt等。如有多个网页都要用到公用信息,可以将公用信息放在包含文件中,实现代码重用,不必在每个文件中都书写。包含文件可以使程序结构清楚,提高编程效率,对网页的编写有很大的好处。以下是一个Include例子。
【例4.5.2】使用包含文件进行网络导航实例。
Include. asp程序代码如下:

Include. asp程序输入界面如图4.5.3所示。当把<!——#Include File="Include.asp"->语句分别插入到4-5-1_1.asp、4-5-1_2.asp、4-5-1_3.asp三个文件中,例如以下4-5-1_1.asp所做更改。
4-5-1_1. asp文件内容改成如下:

重新运行4-5-1.asp程序,选择列表中“古巴共和国”项,显示结果如图4.5.4所示。单击相应项即可前后链接导航。

图4.5.3 Include.asp程序运行结果

图4.5.4 重新选择“古巴共和国”项运行结果