1 / 43

第 8 章 Web 编程技术

第 8 章 Web 编程技术.  本章学习目标:. 1 .通过本章的学习,了解 JavaScript 脚本的编写方法; 2 .能使用 JavaScript 编写简单的脚本; 3 .了解什么是 ASP 、 JSP ,它们同 JavaScript 的关系如何; 4 .理解 ASP 的语法; 5 .使用 Access 数据库编制简单的数据库文件; 6 .能用 FrontPage 和记事本编写 ASP 程序; 7 .能用 Dreamweaver. UltraDev 4.0 和记事本编写 JSP 程序。. 8.1 JavaScript.

nonnie
Download Presentation

第 8 章 Web 编程技术

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章 Web编程技术

  2. 本章学习目标: • 1.通过本章的学习,了解JavaScript脚本的编写方法; • 2.能使用JavaScript编写简单的脚本; • 3.了解什么是ASP、JSP,它们同JavaScript的关系如何; • 4.理解ASP的语法; • 5.使用Access数据库编制简单的数据库文件; • 6.能用FrontPage和记事本编写ASP程序; • 7.能用Dreamweaver. UltraDev 4.0和记事本编写JSP程序。

  3. 8.1 JavaScript

  4. 8.1.1 一个最简单的JavaScript脚本 • <html> • <head> • <title>JavaScript练习</title> • </head> • <body> • </body> • </html>

  5. <script language="JavaScript"> • alert ("Warning!我是JavaScript初学者!"); • </script>

  6. 8.1.2 改变背景颜色 • <script language="JavaScript"> • var MyColor; • MyColor=prompt("您最喜欢的颜色是:",""); • switch(MyColor) { • case "红色": • document.bgColor="red"; • break; • case "黄色": • document.bgColor="yellow";

  7. break; • case "灰色": • document.bgColor="gray"; • break; • default: • alert("我不认识这些颜色!"); • } • </script>

  8. 8.1.3 显示日期和时间 • <script language="LiveScript"> • today = new Date() • document.write("现在时间是: ",today.getHours(),":",today.getMinutes()) • document.write("<br>今天日期为: ", today.getMonth()+1,"/",today.getDate() • ,"/",today.getYear()); • </script>

  9. 8.1.4 弹出新窗口。 • <script language="JavaScript"> • window.open("time.htm", "日期"); • </script>

  10. 8.1.5 表单和函数 • <html> • <head> • <script language="LiveScript"> • function WinOpen() { • window.open("time.htm", "日期"); • } • </script> • </head>

  11. <body> • <form> • <input type="button" name="Button1" value="看看时间" onclick="WinOpen()"> • </form> • </body> • </html>

  12. 8.1.6 用JavaScript编制在线练习题目 • 英语形成性练习题 • 单向选择题,每题20分,共100分 • 1、You have to ___ your younger brother since mother is not at home. • take care • take after • look after • 2、You have to ___ the registration form in order to use that website. • carry on • fill in • keep up • 3、David, please ___ these books ___ to the libarary. • take / back • take / off • take / out

  13. 4、If it rains, they will have to ___ the picnic. • go through • put off • set off • 5、I like ___ the radio. • listening at • listening for • listening to

  14. <script language="JavaScript"> • function cal(theForm) { • var score=0; • if (theForm.R1.value =="c") score++; • if (theForm.R2.value =="b") score++; • if (theForm.R3.value =="a") score++; • if (theForm.R4.value =="b") score++; • if (theForm.R5.value =="c") score++; • alert ("你的得分是:"+score*20+"分"); • } • </script>

  15. 8.2 ASP技术

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

  17. 4. 服务器支持 • Personal Web Server • IIS • 服务器中必须安装FrontPage 服务器扩展支持

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

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

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

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

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

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

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

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

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

  27. 8.2.5 ASP编程示例

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

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

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

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

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

  33. 3、数据库操作

  34. 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;"

  35. 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("谢谢!数据添加成功。") • %>

  36. 8.2.6 在线考试

  37. 8.3 JSP技术 • 开发环境: • Java 2+Apache Tomcat

  38. 8.3.1 JSP初步 • 1.一个最简单的JSP程序 • <%="您好!" %>

  39. 2.在浏览器中显示日期和时间 • 您好,现在的时间是:<%= new java.util.Date() %>

  40. 3.两个页面合并 • <%@ include file="firstjsp.jsp" %>

  41. 4.获取客户端浏览器的版本 • 您的浏览器版本是:<%= request.getHeader("User-Agent") %>

  42. 5.一个简单的留言本 • result.jsp • <%@ page import = "java.io.*, java.util.*" %> • <html> • <head> • <title>谢谢留言</title> • </head> • <body> • 感谢您的留言,按下面链接返回:<br><a href="guestbook.htm">返回</a> • <% • String yourName = request.getParameter( "T1"); • String yourComment = request.getParameter("S1"); • File file = new File ("D:/Program Files/Apache Tomcat 4.0/webapps • /ROOT/exercise/mydata.txt"); • FileWriter fw = new FileWriter(file,true); • PrintWriter pw = new PrintWriter(fw); • pw.println(yourName + yourComment); • pw.close(); • fw.close(); • %> • </body> • </html>

  43. 8.3.2 用JSP开发在线考试程序示例 • 1.数据库的建立 • 2.新站点的定义 • 3.表单的设计 • 4.连接数据库 • 5.设置登录页面 • 6.创建一个记录 • 7.测试

More Related