1 / 56

新視覺化程式設計開發工具 主題: ASP 基本物件

新視覺化程式設計開發工具 主題: ASP 基本物件. 國立台灣師範大學 工業教育研究所 戴建耘教授 龍清榮主任 吳美華組長 主要參考書目 Microsoft Office 97 Visual Basic 自學手冊(碁峰) 微軟 Intranet 原始程式解密 -Vision Module (恆逸) Visual Basic 與 SQL Server (松崗) Microsoft Visual Basic 6.0 程式開發手冊(松崗) Microsoft Visual Basic 6.0 Reference Library ( 松崗). 學習目標:

eileen
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基本物件 國立台灣師範大學 工業教育研究所 戴建耘教授 龍清榮主任 吳美華組長 主要參考書目 Microsoft Office 97 Visual Basic 自學手冊(碁峰)微軟Intranet原始程式解密-Vision Module(恆逸) Visual Basic 與 SQL Server(松崗) Microsoft Visual Basic 6.0 程式開發手冊(松崗) Microsoft Visual Basic 6.0 Reference Library(松崗)

  2. 學習目標: HTTP 的傳輸理論 Request 物件 Response 物件 Application 物件 Session 物件 Server 物件 Active Server Page 物件

  3. HTTP 的傳輸理論

  4. ASP 的基本物件 註:當物件有一組相關特性定義成一種類別,則類別稱為 集合(Collection) 。Request及Response都自己的集合 ,甚至其他物件也有自己的集合,但Application物件 卻只有事件或方法。

  5. Request物件 HTTP 訊息架構 標題 本文

  6. Request 五種類型的集合

  7. Request 四種傳送訊息方式

  8. Request.ServerVariables("SERVER_NAME") ServerVariables 物件取用SERVER_NAME變數,得知伺服器名稱 <A HREF="http://<%= Request.ServerVariables("SERVER_NAME")%>/ MyPage.asp">Link to MyPage</A> 產生超連結到自己網站 Request("SERVER_NAME") 不透過集合直接取用變數值

  9. QueryString集合 取得HTTP要求訊息中使用者所傳送的資料 語法 Request.QueryString(變數名稱 )[(陣列索引值 ) | .Count] http://name_age.asp?name=Frank+Yin&age=24&sport=basketball&sport=baseball URL ? 傳送訊息 & 傳送訊息 & 傳送訊息 & 傳送訊息 TheName = Request.QueryString("name") TheAge = Request.QueryString("age")

  10. TheSport1 = Request.QuertString("sport")(1) TheSport2 = Request.QuertString("sport")(2) 將sport變成陣列 Request.QueryString("sport").Count 取得陣列長度 msg = Request.ServerVariables("QUERY_STRING") 取得問號之後完整傳送訊息

  11. Form集合 從HTML表單中取得供應給伺服器端的輸入欄位 Input.htm程式 傳送方法

  12. Submit.asp程式

  13. 鍵入姓名 選擇顏色 按傳送 結果

  14. ClientCertificate集合 語法 Request.ClientCertificate (設定鍵值 [子欄位])

  15. ClientCertificate 集合的設定鍵值

  16. ServerVariables集合 定義環境變數,讀取伺服器訊息,變數是唯讀, 無法設定。 ServerVariables 的 HTTP 變數

  17. Response 物件 • Response只有Cookies 集合 Response 常用屬性表

  18. Response 常用的方法

  19. Write方法的使用 <%For Each Item In Request.Form Response.Write Item Next %> 透過迴圈顯示HTTP 要求中所有表單的欄位內容 <% Response.Write "<TABLE WIDTH = 100%\>" %> 在HTML >網頁中加上HTML標註 Write方法送出的字串不可以包含"%>" 的字串

  20. Redirect方法的使用 取得目前的螢幕解析度 <% If Request.ServerVariables("HTTP_UA_PIXELS") = "640x480" Then Response.Redirect "lo_res.htm" Else Response.Redirect "hi_res.htm" End If %> 改變所要顯示的網頁

  21. Buffer錯誤處理 Response.Buffer = TRUE 啟動緩衝功能 On Error Resume Next 'code that may cause an unrecoverable error, 'such as failing to open a data connection If Err.number <> 0 Then Response.Clear 錯誤時清除緩衝區內容 Response.Redirect “error.htm”將網頁轉到錯誤訊息 End If畫面

  22. Cookies 集合 • Cookie作用是在提供記錄狀態功能,狀態是以 • 檔案的形式存在使用者的電腦中,檔案通常是 • 放在Cookies資料夾中。 • 透過cookie的機能,可建立和使用者相關的資 • 訊。利用Cookies 集合建立或收集使用者的 • cookie。

  23. <% Response.Cookies("city")="Redmond" %> 程式中送出cookie Response.Cookies("city").Path = "/" 適用在Web 程式所有網頁中 Response.Cookies("Type").Expires = "7/31/1997" 設定cookie過期的期限

  24. Application 物件 1.讓資訊分享給所有網站應用程式上使用者 ,當網頁第一次被開啟後,任何使用這個 ASP檔的使用者都可使用到同一個 Application變數。 2.生命期會從第一個使用者下載網頁開 始, 一直到伺服器關閉為止。

  25. 計算本站拜訪人次

  26. 執行結果

  27. Application物件鎖定及解除 兩個使用者同時在網站上使用同一個變數,變數網站無法區別,為了避免這樣的錯誤發生,利用Lock以及Unlock方法來解決其中的衝突。 用Lock以及Unlock方法來更改Web應用程式的造訪次數 <% Application.Lock Application("NumVisits") = Application("NumVisits") + 1 Application.Unlock %> 這個網站造訪的次數為: <%= Application("NumVisits") %> 人次

  28. Application物件的使用 • Session物件的儲存值僅適用於該次連線過程中 • 的那位使用者。 • Application 物件中儲存值則適用所有連線的使 • 用者,直至Web 伺服器關閉為止。 資訊寫入Application 物件,之後在其他網頁顯示訊息 <% Application("TodaysLecture") = Request.Form("lecture") Application("location") = Request.Form("location")%> 其他的網頁顯示 請不要錯過演講,地點位在: <%= Application("location") %>, 演講主題: <%= Application("TodaysLecture") %>

  29. Application的事件 Application_OnStart、Application_OnEnd、Session_OnStart或Session_OnEnd都要放在global.asa 在global.asa檔中加入Application_OnStart的事件 <SCRIPT LANGUAGE=VBScript RUNAT=Server> Sub Application_OnStart '處理程式碼 End Sub </SCRIPT>

  30. Session 物件 1.提供給個別使用者個別的變數,允許獨 立的建立Session變數。 2.利用Session物件可存放單一個使用者通 訊過程的資訊,當多個使用者上同一網 頁時,則每一個使用者都會有獨立使用 Session物件來存放變數,且不能夠和其 他使用者分享。

  31. 用Session變數來計數網頁下載次數

  32. 執行結果

  33. Server 物件 1.Server 物件允許我們存取Web伺服器上的各種訊 息,也可以設定Server-Side Script的Timeout值。 2.最常利用CreateObject 方法來建立伺服器上的軟 體元件。 建立BrowserType程式元件 <% Set bc = Server.CreateObject("MSWC.BrowserType") %>

  34. Active Server Page 的物件 ASP 的元件

  35. Database Access元件 (ActiveX Data Object) 與ODBC 配合在網站上公佈索取資料庫 內容,必須與Server物件的CreateObject 方法配合,來建立Connection 物件。

  36. 開啟資料庫 執行Customer表格 連接ODBC

  37. 建立與SQL Server的Connection 物件,執行SQL查詢語法SELECT ,將結果放在RS裡,再使用迴圈將標題及RS的內容列出。

  38. 執行結果

  39. File Access元件 由可開啟及關閉檔案的FileSystem ,及可用來讀取及寫入文字的TextStream兩個元件組成 瀏覽器每次開啟時會有不同的問候語 Hello.txt程式

  40. Hello.asp程式 開啟檔案

  41. 讀取檔案 路徑更改 跳行

  42. 讀取一個字串

  43. 執行結果

  44. 實作ASP基本物件 1.請建立名稱為aspform.asp檔,內容如下: <html> <head> <title>GET 傳送訊息方式</title> </head> <body> <form action="asp1b.asp" method=GET> 姓名:<INPUT TYPE=TEXT NAME="input1"> <p>特徵: <select name="input2"> <OPTION>戴眼鏡 <OPTION>小肚微凸 <OPTION>漂亮 </select> <p><input type=submit VALUE="寫完了"> </form> </body> </html>

  45. 2.再請建立名稱為asp1b.asp檔: <% @ LANGUAGE="VBScript"%> <HTML> <BODY> <%= Request.QueryString("input1") %> 您好, 您的特徵是 <%= Request.QueryString("input2") %> </BODY> </HTML> 3.檢視執行結果。

  46. Q & A • Q: ASP的基本物件有那五種? • A: Request • Response • Session • Application • Server

  47. Q & A • Q: 在Application物件,當中兩個使用者 • 同時在網站上使用同一個變數,變數 • 網站無法區別,為了避免這樣的錯誤 • 發生,可利用什麼方法來解決其中的 • 衝突? • A: Lock以及Unlock

More Related