1 / 27

8.2 ASP 技术

8.2 ASP 技术. 8.2.1 ASP 的语法. 1、编制的语言 VBScript JavaScript 2、格式: <%  开始 %>  结束 3、工具:记事本  FrontPage2000/XP Dreamweave Ultradev. 4. 服务器支持 Personal Web Server IIS 其他. 8.2.2 数据库的建立. Access 数据库的操作和使用. 8.2.3 在 ASP 中使用 SQL 语法示例. 连接数据库

dom
Download Presentation

8.2 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. 8.2 ASP技术

  2. 8.2.1 ASP的语法 • 1、编制的语言 • VBScriptJavaScript • 2、格式: • <% 开始 • %> 结束 • 3、工具:记事本 FrontPage2000/XP Dreamweave Ultradev

  3. 4. 服务器支持 • Personal Web Server • IIS • 其他

  4. 8.2.2 数据库的建立 • Access数据库的操作和使用

  5. 8.2.3 在ASP中使用SQL语法示例 • 连接数据库 • strProvider = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=将该段文字替换为本地硬盘上数据库的路径;" • Set objConn = server.createobject("ADODB.Connection") • objConn.Open strProvider

  6. DELETE • strCommand = "DELETE FROM Customers WHERE LastName = 'Smith'" • objConn.Execute strCommand

  7. SELECT • sql1="select * from online where 姓名='" & name & "' and passwd='" & passwd & "'" • set rs=objConn.execute(sql1)

  8. UPDATE • strCommand = "UPDATE online SET 平时1 = '" & score & "' WHERE 姓名 = '" & name & "' " • objConn.Execute strCommand

  9. INSERT • strCommand = "INSERT INTO Customers (FirstName, LastName) VALUES ('Jose','Lugo')" • objConn.Execute strCommand

  10. 8.2.4 ASP中的对象 • 1.Response • 该对象用来向文档中输出服务器执行程序的结果 • 2.Request • 该对象用来获取用户的相关信息

  11. 3.Application • ASP中的Application对象是用来存储各种变量的 • 4.Session • Session对象也是用来存储各种信息的,但该对象只是针对单一用户而言

  12. 5.Server • 该对象用来获取服务器中的属性和方法 • 6.Error • 该对象用来显示一个ASP页面错误的详细信息

  13. 8.2.5 ASP编程示例

  14. 1、最简单的ASP • <%@ Language=JScript %> • <font face="MS Gothic"> • <% • var strGreeting; • strGreeting = "Hello World!"; • %> • <%=strGreeting%>

  15. 用VBScript • <% • strGreeting=“Hello, World!” • %> • <%= strGreating %>

  16. 简化一下: <%=“Hello,World!”%>

  17. 2、显示时间 • <%@ Language=JScript %> • <% • var months; • var hours; • today = new Date(); • months = today.getMonth()+1; • hours =today.getHours(); • if (hours <12){ • %> • <%= "早上好!" %>

  18. <% • }else if (hours < 18) { • %> • <%= "下午好!"%> • <% • }else if (hours < 24) { • %> • <%= "晚上好!" %> • <% • } • %>

  19. 用VBScript • <% • Dim dtmHour • dtmHour = Hour(Now()) • If dtmHour < 12 Then • strGreeting = "早上好!" • Else     • strGreeting = "您好!" • End If   • %> • <%= strGreeting %>

  20. 进一步修改 • <% • ‘下面增加时间参数 • dtmYear=Year(Now()) • dtmMonth=Month(Now()) • dtmDay=Day(Now()) • dtmHour = Hour(Now()) • dtmMin=Minute(Now()) • dtmsec=Second(Now())

  21. If dtmHour < 12 Then • strGreeting = "早上好!" • Else • strGreeting = "您好!" • End If • %> • <%= "现在的时间是:" &dtmHour & "时" & dtmMin & "分" & dtmsec &"秒<br>今年是:" & dtmYear & "年" & dtmMonth & "月" & dtmDay &"日<br>" %> • <%= strGreeting %>

  22. 3、一个简单的留言本 • 1、表单的制作 • <form method="POST" name="guestbook" action ="gresult.asp">

  23. 2、用Access制作数据库 • 数据库名称: guestbook.mdb • 字段:姓名、留言

  24. 3、数据库操作

  25. 4、gresult.asp代码 • <% • dim strTB1, strTB2, strCommand • strTB1 =Server.HTMLEncode(Request.QueryString("name")) • strTB2 =Server.HTMLEncode(Request.QueryString("content")) • strProvider = "Provider=Microsoft.JET.OLEDB.4.0;Data • Source=D:\InetPub\Wwwroot\fpdb\guestbook.mdb;"

  26. Set objConn = server.createobject("ADODB.Connection") • objConn.Open strProvider • strCommand = "INSERT INTO guest(姓名,留言) VALUES ('" • strCommand = strCommand & strTB1 & "','" & strTB2 • strCommand = strCommand & "')" • objConn.Execute strCommand • Response.Write("谢谢!数据添加成功。") • %>

  27. 8.2.6 在线考试

More Related