1 / 34

第7章 ASP 的内置组件

第7章 ASP 的内置组件. 7.1 ASP 的内置组件概述 7.2 广告轮显组件 7.3 内 容 轮 显 组 件 7.4 文件超链接组件 7.5 网页计数器组件. 本章主要介绍 ASP 的内置组件。通过本章的学习,读者应该掌握以下内容:  广告轮显组件  内容轮显组件  文件超链接组件  网页计数器组件. 7.1 ASP 的内置组件概述. 要创建一个组件对象,通常用 ASP 提供的 Server.CreateObject() 方法。. 7.2 广告轮显组件. 1 .创建广告轮显组件的实例对象

ermin
Download Presentation

第7章 ASP 的内置组件

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第7章 ASP的内置组件 • 7.1 ASP的内置组件概述 • 7.2 广告轮显组件 • 7.3 内 容 轮 显 组 件 • 7.4 文件超链接组件 • 7.5 网页计数器组件

  2. 本章主要介绍ASP的内置组件。通过本章的学习,读者应该掌握以下内容: 本章主要介绍ASP的内置组件。通过本章的学习,读者应该掌握以下内容: •  广告轮显组件 •  内容轮显组件 •  文件超链接组件 •  网页计数器组件

  3. 7.1 ASP的内置组件概述 • 要创建一个组件对象,通常用ASP提供的Server.CreateObject()方法。

  4. 7.2 广告轮显组件 1.创建广告轮显组件的实例对象 • 使用AdRoatate组件首先要创建一个AdRoatate组件的实例——AdRoatate对象: • Set 实例对象名=Server.CreateObject("MSWC.AdRotate")

  5. 2.广告轮显组件的属性和方法 • 广告轮显组件的属性和方法分别如表7-1、表7-2所示。

  6. 3.使用广告轮显组件 • 要使用广告轮显组件,需要以下3个文件。 • ① 广告信息文本文件:记录所有广告信息的文本文件。 • ② 超链接处理文件:引导客户到相应广告网页的ASP文件。 • ③ 显示广告图片文件:这是放置广告图片的文件,比如个人主页等。

  7. 例7-1 建立广告信息文本文件。 • redirect 7-2.asp • width 440 • height 260 • border 1 • * • ../pic/010.gif • ../chap2/ch2-1.htm • 第2章例2-1 • 20

  8. ../pic/025.gif • ../chap2/ch2-2.htm • 第2章例2-2 • 30 • ../pic/028.gif • ../chap2/ch2-3.htm • 第2章例2-3 • 40

  9. 例7-2 建立超链接处理文件。 • <% • url=request("url") • response.redirect url • %>

  10. (3)建立显示广告图片文件 • 例7-3 建立显示广告图片。 • <html> • <head> • <title>显示广告图片实例</title> • </head> • <body> • <h2 align=center>个人主页</h2> • <p align=center>

  11. <% • set objad=server.createobject("mswc.adrotator") • broder=1 • objad.clickable=true • objad.targetframe="target='_blank'"

  12. response.write objad.getadvertisement(7-1.txt") • set objad=nothing • %> • </body> • </html>

  13. 7.3 内 容 轮 显 组 件 1.创建内容轮显组件的实例对象 • 使用Coutent Rotator组件首先要创建一个Coutent Rotator组件的实例——Coutent Rotator对象: • Set 实例对象名=Server.CreateObject("MSWC. Coutent Rotator")

  14. 2.内容安排文件 • 文件格式如下: • %%[#n[//注释]]

  15. 3.使用内容轮显组件实例 • (1)建立框架结构的主文件 • 例7-4 设计随机文本播放器的框架网页(main.asp)。 • 建立一个具有左右两个框架窗口的框架网页(main.htm),左部为随机文本播放器,用来显示内容安排文件设定的网页信息,对应文件为left.asp;右部框架用来显示个人主页,对应文件为home.asp。

  16. 框架网页main.htm的代码如下: • <html> • <head> • <title>框架链接的变化</title> • </head>

  17. <frameset cols="30%,70%"> • <frame name="contents" src=../chap7/left.asp> • <frame name="main" src=../chap7/right.asp> • </frameset> • </html>

  18. (2)建立内容轮显的随机文本播放器 • 例7-5 建立随机文本播放器的主程序(left.asp)。 • <html> • <head> • </head> • <body>

  19. <% • set content=server.CreateObject("MSWC.ContentRotator") • response.write Content.ChooseContent("text.txt") • Set Content=nothing • %> • </body> • </html>

  20. 3)建立内容轮显的文本文件 • 例7-6 建立内容轮显的文本文件(text.txt)。 • %%#2//这是第一条记录 • <font color=blue>欢迎访问我的个人主页</font> • %%#2//这是第二条记录 • <font color=red>请您一定提出宝贵意见!</font>

  21. %%#2//这是第三条记录 • <font color=green>您可以随时与我联系,和您共同探讨难题。</font> • <ul> • <li>ASP内置对象 • <li>ASP内置组件 • </ul>

  22. (4)建立右框架文件 • 例7-7 建立右框架内容文件(right.asp)。 • <html> • <head> • </head> • <body> • <h1>我的主页 </h1> • 内容轮显组件的使用 • </body> • </html>

  23. 7.4 文件超链接组件 1.创建文件超链接组件的实例对象 • 使用nextlink组件首先要创建一个nextlink组件的实例——nextlink对象: • Set 实例对象名= Server.CreateObject("MSWC.nextlink") 2.文件超链接组件的方法

  24. 例7-8 建立超链接数据文件(link.txt)。 • ../chap2/ch2-5.htm 第2章例2-5--字体 • ../chap2/ch2-6.htm 第2章例2-6--段落 • ../chap2/ch2-7.htm 第2章例2-7--水平线

  25. 例7-9 文件超链接组件应用。 • <html> • <head> • <title>文件超链接组件应用</title> • </head> • <body> • <h2 align=center>第2章实例</h2> • <p align=center>

  26. <% • dim link '声明一个组件实例变量 • dim i,sum • set link=server.createobject("mswc.nextlink") '创建实例 • sum=link.getlistcount("link.txt") • '返回文件总数 • for i=1 to sum • '用循环写出所有文件的链接 • %>

  27. <a href="<%=link.getnthurl("link.txt",i)%>" target="_blank"> • '显示链接文件中第n个文件的地址 • <%=link.getnthdescription("link.txt",i)%></a><br> • '显示链接文件中第n个文件的描述 • <% next %> • </body> • </html>

  28. 7.5 网页计数器组件 • 网页计数器组件用于统计每个网页被访问的次数,该组件定期把统计的数据存入服务器磁盘上的一个文本文件,即访问次数统计数据文件中,所以在停机或出现错误信息时,当前数据也不会丢失。

  29. 1.创建网页计数器组件的实例对象 • Set 实例对象名= • Server.CreateObject("MSWC.PageCounter") 2.Page Counter对象的方法

  30. 例7-10 计数器组件的应用。 • <html> • <head> • <title>计数器组件的应用</title> • </head> • <body> • <h2 align=center>2004年名车展</h2> • <p align=center>

  31. <% • dim count '声明一个组件实例变量 • set count=server.createobject("mswc.pagecounter") • count.pagehit() • '将当前网页访问次数加1 • dim visit_num

  32. visit_num=count.hits() • '获取当前网页访问次数 • response.write "您是本站点的第"&cstr(visit_num)&"位访客" • %> • </body> • </html>

More Related