1 / 54

第四讲 Asp 内置对象

第四讲 Asp 内置对象. Asp 内置对象. ASP 编程代码包括两部分: 1 、一种脚本语言 2 、一组内置对象. 使用 VBSCRIPT 编写的 ASP 程序:. <HTML> <BODY> <% select case Request.Form("add") case "tsinghua" Response.Redirect "http://www.tsinghua.edu.cn" case "yahoo" Response.Redirect "http://www.yahoo.com" case "sina"

sylvie
Télécharger la présentation

第四讲 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. 第四讲 Asp内置对象

  2. Asp内置对象 ASP编程代码包括两部分: 1、一种脚本语言 2、一组内置对象

  3. 使用VBSCRIPT编写的ASP程序: <HTML> <BODY> <% select case Request.Form("add") case "tsinghua" Response.Redirect "http://www.tsinghua.edu.cn" case "yahoo" Response.Redirect "http://www.yahoo.com" case "sina" Response.Redirect "http://www.sina.com.cn" end select %> </BODY> </HTML>

  4. Asp内置对象 • Active Server Pages (ASP) 结构五个重要的内建对象: • Request • Response • Server • Session • Application

  5. 用户请求信息 TCP/IP HTTP请求 反馈信息 HTTP响应 WEB服务器 Request与Response Request Response ASP 浏览器 • Request 读用户的输入信息 • Response 向用户输出信息

  6. 一、功能概述: Request对象 Request 对象在 HTTP 请求期间,检索客户端浏览器传递给服务器的值 。 语法 Request[.collection|property|method](variable) 集合: ClientCertificate 存储在发送到 HTTP 请求中客户端证书中的字段值。 Cookies HTTP 请求中被发送的 cookie 的值。 Form HTTP 请求正文中表格元素的值。

  7. QueryString HTTP 中查询字符串中变量的值。 预定的环境变量的值。 ServerVariables 属性 TotalBytes 只允许读。指定客户端在请求正文中发送的字节总数。 方法 BinaryRead 检索从客户端发送到服务器作为 POST 请求的一部分的数据。

  8. Request querystring 当用get方法提交表单,数据 被保存在querystring集合中 语法: Request.querystring(变量).[index|.count]

  9. Request 例子: 文件:4-6.htm <html> <body > <form method="get" action="4-6.asp"> 姓名: <input type="text" name="name"> <br> 密码: <input type="password" name="pwd"><br> 性别: <select name="gender"> <option>男</option> <option>女</option> </select> <br> <input type="submit" name="Submit" value="提交"> <input type="reset" name="Submit2" value="重置"> </form> </body> </html>

  10. Request 例子: 文件:4-6.ASP <%@ Language=VBScript %> <% Response.Expires=0 Sname =Request.QueryString("name") Spwd =Request.QueryString("pwd") SGender =Request.QueryString("gender") %> <HTML> <BODY> 姓名: <%= Sname%><Br><Br> 密码: <%= Spwd%><Br><Br> 性别: <%= SGender%><Br><Br> URL后面的字符串: <Br> <%= Request.ServerVariables("Query_String")%> </BODY> </HTML>

  11. Request Form 当用POST方法提交表单,数据 被保存在Form集合中 语法:request.Form(元素)[.index|.count] 元素:表单元素名称 Index:表单多值中 1~request.form(参数).Count中的一个 Count:集合中元素的个数

  12. Request Form 集合例子: 文件(4-7.htm) <html> <body> <form method="post" action="4-7.asp"> 姓名: <input type="text" name="yourname"><br> 性别: <select name="gender"> <option>男</option> <option>女</option> </select> <br> 爱好(可多选):<br> <input name="hobby" type="checkbox" value="电脑">电脑 <input name="hobby" type="checkbox" value="游戏">游戏 <input name="hobby" type="checkbox" value="体育">体育 <input name="hobby" type="checkbox" value="阅读">阅读 <br> 留言: <textarea name="message"> </textarea> <br> <input type="submit" name="Submit" value="提交"> <input type="reset" name="Submit2" value="重置"> </form> </body> </html>

  13. Request Form 集合例子: 文件(4-7.asp) <%@ Language=VBScript %> <% Response.Expires=0 SName = Request.Form("yourname") SGender = Request.Form("gender") SM =Request.Form("message") SMsg = Replace(SM,vbcrlf,"<Br>" & vbcrlf) %> <HTML> <BODY> 姓名: <%= SName%><Br><Br> 性别: <%= SGender%><Br><Br> <% Response.Write "爱好:<Br>" For I = 1 to Request.Form("hobby").Count Response.Write Request.Form("hobby")(I) & "<Br>" Next %><Br>留言: <Br> <%= SMsg%> </BODY> </HTML>

  14. Request ServerVariables 服务器的环境变量 语法:Request.ServerVariables(服务器变量)

  15. Request Cookie 取得HTTP的cookie值 Mycookie1=sugar Mycookie2=TYPE1=sugar&TYPE2=ginger 语法:request.Cookies(cookie)[.(关键字)|.haskeys

  16. Request Cookie 例子: <% nickname=Request.Form("nick") Response.Cookies("nick")=nickname ' 用 response 对象将用户名写入 Cookie 之中 Response.Write " 欢迎 "&Request.Cookies("nick")&" 光临!" %> <html> <head> <title>cookie</title> </head> <body> <form method="POST" action="4-8.asp"> <p><input type="text" name="nick"> <input type="submit" value=" 提交 " name="B1"> <input type="reset" value=" 重填 " name="B2"></p> </form> </body> </html>

  17. <% dim Num Num=Request.Cookies("Visit_num") if Num>0 then Num=Num+1 Response.write "您已是第" & Num & "次访问本站点了。" else Response.write "欢迎您首次访问本站。" Num=1 end if Response.Cookies("Visit_num")=Num %>

  18. 有时在一个页面中可能需要定义很多个Cookies变量,为了更好地管理它, 在Cookies组件中常引入概念“子键”。引用它的语法如下: Request.Cookies("变更名")("子键名") 如下面的Cookie其中保存了三个键值: <% Response.Cookie("info")("Myname")="jeff" Response.Cookie("info")("Gender")="male" Response.Cookie("info")("Myheight")="172" %>

  19. 事实上客户机上的Cookie字典是以字符串的形式存在: info=Myname=jeff&Gender=male&Myheight=172 如果用户没有指定“子键”名而直接引用Cookies变量, 将会返回一个包含 所有的“子键”名及值的字符串。 例如上面这个例子包含三个“子键”: “Mynam e”、“Gender”和“Myheight”, 当用户没有指定其“子键”而直接通过 Request.Co okies(“info”)来引用时, 则会得到下列字符串: info=Myname=jeff&Gender=male&Myheight=172

  20. Asp内置对象 -----response

  21. Response对象 • Response对象用于动态响应客户端请求(Request),并将动态生成的响应结果返回到客户端浏览器中。 • Response的使用语法为: • Response.collection|property|method

  22. 属性 功能说明 Buffer 表明页输出是否被缓冲 CacheControl 决定代理服务器是否能缓存ASP生成的输出 Charset 将字符集的名称添加到内容类型标题中 ContentType 指定响应的HTTP内容类型 Expires 在浏览器中缓存的页面超时前,指定缓存的时间 ExpiresAbsolute 指定浏览器上缓存页面超时的日期和时间 IsClientConnected 表明客户端是否与服务器断开 Status 服务器返回的状态行的值 • Response对象的属性

  23. 方法 功能说明 AddHeader 从名称到值设置HTML标题 AppendToLog 在该请求的Web服务器日志条目后添加字符串 BinaryWrite 将给出信息写入到当前HTTP输出中,并且不进行任何字符集转换 Clear 清除任何缓冲的HTML输出 End 停止处理.asp文件并返回当前的结果 Flush 立即发送缓冲的输出 Redirect 将重指示的信息发送到浏览器,尝试连接另一个URL Write 将变量作为字符串写入当前的HTTP输出 • Response对象的方法

  24. Response对象 • 1.Write方法: 可以向浏览器输出动态信息。 格式: Response.Write 任何数据类型 Response.Write(任何数据类型)

  25. Response.write 基本用法:(一个简单例子) <%@Language=VBScript%> <html> <head><title>Response.Write的基本用法</title></head> <body> <% Response.Write"<p>你好!!" t=now() Response.Write"<p>现在是:"& t &"<br>" cht1="谢谢!" cht2="欢迎光临!" Response.Write cht1 & cht2 %> </body> </html> 4-2.asp

  26. 第五讲数据库基础知识

  27. 讲解提纲 • 7.1 数据库的基本概念 • 7.2 建立Access数据库 • 7.3 SQL语言简介

  28. 7.1数据库的基本概念

  29. 7.1.1数据库管理技术的发展阶段 • 人工管理 • 文件管理 • 数据库管理

  30. 7.1.2数据库的基本术语 • 字段、记录、值、表、数据库、数据模型

  31. 7.1.3数据库管理系统 • 大中型关系型数据库管理系统有SQL Server、IBM DB2、Oracle、SyBase、Informix等,常用的小型数据库管理系统有Access、Pradox、Foxpro等。 • 在ASP中一般使用SQL Server或Access数据库。 • 本书主要使用Sql server。

  32. 7.2建立sql server数据库

  33. 7.2.1规划数据库 • 主要是规划每一个表的字段和字段类型,不要有冗余。

  34. 7.2.2新建一个数据库 • 依次选择菜单命令【开始】、【程序】、【Microsoft access】就可以启动Access2000

  35. 7.2.3 新建和维护表 • 在上图双击【使用设计器创建表】选项,就可以打开新建表的设计视图。

  36. 在表中输入数据 • 在主窗口中双击表名,就可以打开输入窗口

  37. 7.2.4 新建和维护查询 • 利用查询可以更方便的更改分析和处理数据。查询就好比是一张虚拟的表一样,用户可以像在表里操作一样,输入数据或浏览数据。 • 查询有很几种:简单查询、组合查询、计算查询和条件查询。现在就来建立一个简单查询,只显示姓名和Email两个字段的内容。

  38. 新建简单查询 • 在Access主窗口左侧选择”查询”按钮

  39. 显示查询内容 • 在主窗口中双击查询名称

  40. 利用SQL语言建立查询 • 当进行左图时,直接单击【关闭】按钮,然后在主窗口中依次选择【视图】、【SQL视图】菜单命令,就会出现”SQL视图”对话框。

  41. 7.3 SQL语言简介 1.Select语句 查询数据 2.Insert语句 添加记录 3.Delete语句 删除记录 4.Update语句 更新记录

  42. 7.3.1 Select语句 • 此时可以使用Select语句来取得满足特定条件的记录集。也就是说可以从数据库中查询有关记录。 • Select [Top(数值)] 字段列表From 表[Where 条件] [Order By 字段] [Group By 字段]

  43. Select语句示例 • Select * From users • Select real_name,email From users • Select Top 3 * From users • Select real_name,(submit_date+365) As new_date From users • Select * From users Where submit_date<#2003-11-1# AND real_name=“建波”

  44. Select语句示例 • Select * From users Where real_name like “%勇%” • Select * From users Order By real_name DESC • Select Count(*) As total From users Where submit_date<#2003-11-1# • Select users.real_name,day_log.log_date,day_log.IP From users,day_log Where users.user_name=day_log.user_name

  45. 7.3.2 Insert语句 • 向用户表Uesrs中增加新成员时,就需要将新用户的数据插入到表users中。此时,可以使用SQL语言中的Insert语句来实现这个功能。 • Insert Into 表(字段1,字段2,…) Values(字段1的值,字段2的值,…)

  46. Insert语句示例 • Insert Into users ( user_name, password,real_name,tel,email,submit_date) Values(“mengmeng”,”123456”,”萌萌”,”6887150”,”mengmeng@henan.com”, #2003-11-2#)

  47. Insert语句示例 • Insert Into users ( user_name ) Values(“liya”) • Insert Into users ( user_name, real_name ) Values(“feiyun”,”费云”) • Insert Into users ( user_name, submit_date ) Values(“luofang”,#2003-12-5#) • Insert Into users ( user_name, age) Values(“zhangpeng”,23)

  48. 7.3.3 Delete语句 • 在SQL语言中,可以使用Delete语句来删除表中无用的纪录。 • Delete From表[Where 条件]

  49. Delete语句示例 • Delete From users Where user_name=“tutu” • Delete From users Where submit_date<#2003-1-1# And real_name=“李亚” • Delete From users

  50. 7.3.4 Update语句 • 可以使用Update语句来实现更新数据的功能 • Update 数据表名Set 字段1=字段值1,字段2=字段值2,… [Where 条件]

More Related