1 / 30

第 10 章 伺服端元件的使用

第 10 章 伺服端元件的使用. 10-1 Server Side Include 10-2 AdRotator 動態廣告元件 10-3 Browser Capabilities 瀏覽程式元件 10-4 Content Linking 連結元件 10-5 Content Rotator 動態內容元件 10-6 Email 電子郵件元件 10-7 Upload 檔案上傳元件. 10-1 Server Side Include. 10-1-1 SSI 指令說明 10-1-2 使用 SSI 插入 HTML 文件 10-1-3 使用 SSI 插入 ASP 函式庫.

neena
Download Presentation

第 10 章 伺服端元件的使用

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. 第10章 伺服端元件的使用 • 10-1 Server Side Include • 10-2 AdRotator動態廣告元件 • 10-3 Browser Capabilities瀏覽程式元件 • 10-4 Content Linking連結元件 • 10-5 Content Rotator動態內容元件 • 10-6 Email電子郵件元件 • 10-7 Upload檔案上傳元件

  2. 10-1 Server Side Include • 10-1-1 SSI指令說明 • 10-1-2 使用SSI 插入HTML文件 • 10-1-3 使用SSI插入ASP函式庫

  3. 10-1-1 SSI指令說明 - 1

  4. 10-1-1 SSI指令說明 - 2 • ASP程式只支援SSI的Include指令。 • Include指令可以讓我們在ASP程式插入HTML標籤或ASP程式碼檔案,Include指令有兩種Include virtual和Include file,如下所示: <!--#include virtual="/somefile.asp"--> <!--#include file="somefile.asp"-->

  5. 10-1-2 使用SSI 插入HTML文件 • Include指令可以在ASP程式插入HTML文件,例如:在ASP程式的開頭和結束分別插入兩個檔案,如下所示: <html> <head></head> <body> <!-- #include file="Ch10-1-2h.htm" --> …….. <!-- #include file="Ch10-1-2f.htm" --> </body> </html>

  6. 10-1-3 使用SSI插入ASP函式庫 • SSI的Include指令可以插入其它函式庫檔案,副檔名為.inc,如此ASP程式馬上就可以使用程序和函數,如同插入一個ASP函式庫。 <!-- #include file="Ch10-1-3.inc" -->

  7. 10-2 AdRotator動態廣告元件 • 10-2-1 廣告圖片設定檔 • 10-2-2 連結網址的ASP程式 • 10-2-3 顯示廣告圖片的ASP程式

  8. 10-2-1 廣告圖片設定檔 • Ad Rotator元件需要文字設定檔案定義廣告圖片檔名、超連結和處理連結的ASP程式,設定檔案的內容使用星號「*」分隔成兩個部分如下所示: REDIRECT Ch10-2-2.asp …………. * http://localhost/Ch10-2a.gif http://localhost/Ch10-1-2.asp ASP網頁製作徹底研究 10 http://localhost/Ch10-2b.gif http://localhost/Ch10-1-3.asp ASP與IIS 4/5網站架設徹底研究 10 …………………….

  9. 10-2-2 連結網址的ASP程式 • 在AdRotator元件設定檔第一列的REDIRECT指令就是按下圖片後執行的ASP程式,AdRotator元件在轉向到這個ASP程式時,將傳入兩個URL參數,轉向的網址如下所示: http://localhost/Ch10-2-2.asp?url=#2&image=#1 • 我們可以使用下列程式碼取得各參數,如下所示: Request.QueryString("URL")

  10. 10-2-3 顯示廣告圖片的ASP程式 • 在建立好設定檔和連結的ASP程式後,就可以建立AdRotator元件的AdRotator物件顯示廣告圖片,其程式碼如下所示: Set objAd = Server.CreateObject("MSWC.AdRotator") • AdRotator元件的方法只有一個GetAdvertisement,請執行下列指令顯示廣告圖片,如下所示: Response.Write(objAd.GetAdvertisement("Ch10-2-1.txt"))

  11. 10-3 Browser Capabilities瀏覽程式元件 • Browser Capabilities元件可以建立BrowserType物件取出客戶端瀏覽程式的相關資訊,以得知使用者的瀏覽程式到底提供那些功能。 • 在ASP程式使用Browser Capabilities元件取得瀏覽程式資訊時,我們需要建立BrowserType物件,其程式碼如下所示: Set objBrowserCap = Server.CreateObject("MSWC.BrowserType") • 程式碼在建立好物件後,就可以取得屬性值得知瀏覽程式支援的功能。

  12. 10-4 Content Linking連結元件 • 10-4-1 Content Linking元件的使用 • 10-4-2 建立網站目錄 • 10-4-3 建立網站的導覽架構

  13. 10-4-1 Content Linking元件的使用 • 在ASP程式使用Content Linking元件,我們需要建立網站各網頁和ASP程式順序的清單檔,這是一個文字檔案,其內容如下所示: file1.htm 說明文字1 file2.htm 說明文字2 file3.asp 說明文字3 ………..

  14. 10-4-2 建立網站目錄 • 在ASP程式只需使用Do Loop迴路顯示清單檔案的超連結,就可以將清單檔案Ch10-4-2.txt的定義建立成為網站目錄,如下所示: intCount = objNextLink.GetListCount("Ch10-4-2.txt") Do While intI <= intCount strURL = objNextLink.GetNthURL("Ch10-4-2.txt",intI) strName = objNextLink.GetNthDescription("Ch10-4-2.txt",intI) %> <li><a href="<%=strURL%>"><%=strName%></a> <% intI = intI + 1 Loop

  15. 10-4-3 建立網站的導覽架構 • 在定義好清單檔內的每一頁的順序,就可以建立上一頁和下一頁的網站導覽架構,在取得清單檔Ch10-4-3.txt內的所有頁數和目前的頁數,其程式碼如下所示: ' 取得頁數 intMaxPages = objNextLink.GetListCount("Ch10-4-3.txt") ' 取得目前的頁數 intPageNo = objNextLink.GetListIndex("Ch10-4-3.txt")

  16. 10-5 Content Rotator動態內容元件 • 10-5-1 Content Rotator元件的內容定義檔 • 10-5-2 使用Content Rotator元件顯示文件內容

  17. 10-5-1 Content Rotator元件的內容定義檔 • Content Rotator元件可以由文字檔案動態的取出文字內容,這些文字內容可以是HTML標籤或CSS樣式,內容定義檔使用「%%」符號分隔,如下所示: %%1 文字內容1 %%2 文字內容2 %%3 文字內容3

  18. 10-5-2 使用Content Rotator元件顯示文件內容 • 在建立好內容定義檔後,可以建立Content Rotator元件的ContentRotator物件,其程式碼如下所示: Set objContentRotator = Server.CreateObject("MSWC.ContentRotator") • 程式碼在建立好物件後,我們可以使用方法取得定義檔的內容,只需使用Response.Write方法,就可以顯示Content Rotator元件動態取得的文字內容,如下所示: Response.Write(objContentRotator.ChooseContent("Ch10-5-1.txt"))

  19. 10-6 Email電子郵件元件 • 10-6-1 Dundas Mailer Control郵件匣道元件 • 10-6-2 安裝Dundas Mailer Control元件 • 10-6-3 使用Dundas Mailer Control元件寄送電子郵件

  20. 10-6-1 Dundas Mailer Control郵件匣道元件 • Dundas Mailer Control 1.0元件是DUNDAS Software公司開發的免費商用ASP郵件匣道元件,支援SMTP、MIME和NNTP通訊協定,可以在IIS或PWS的網頁表單輸入郵件或文章內容,然後使用ASP程式配合外部的郵件伺服器寄送電子郵件和張貼新聞文章。

  21. 10-6-2 安裝Dundas Mailer Control元件 • Dundas Mailer Control元件下載的檔案為一個執行檔【AspMail.exe】,內含安裝程式,直接執行此程式檔案就可以安裝Dundas Mailer Control元件。

  22. 10-6-3 使用Dundas Mailer Control元件寄送電子郵件-1 • 在ASP程式使用Dundas Mailer Control元件在網頁寄送郵件的方法十分容易,只需建立好輸入電子郵件內容的表單,然後在ASP表單處理程式建立Mailer物件寄送電子郵件,如下所示: Set objMail = Server.CreateObject("Dundas.Mailer") • 在上述程式碼建立好物件後,只需設定郵件內容的相關屬性,就可以使用SendMail方法寄送郵件。

  23. 10-6-3 使用Dundas Mailer Control元件寄送電子郵件-2

  24. 10-6-3 使用Dundas Mailer Control元件寄送電子郵件-3 • 在設定好電子郵件的相關屬性後,需要使用Add方法來新增收件者TOs的電子郵件地址,如下所示: objMail.TOs.Add "someone@company.com" • 最後可以執行SendMail方法透過SMTP伺服器寄送電子郵件,然後使用Err資料集合檢查郵件寄送是否有錯誤,如下所示: On Error Resume Next objMail.SendMail If Err.Number <> 0 Then Response.Write("發生錯誤: " & Err.Description & "<br>") End If

  25. 10-7 Upload檔案上傳元件 • 10-7-1 HTML的檔案欄位標籤 • 10-7-2 安裝Dundas Upload Control檔案上傳元件 • 10-7-3 使用Dundas Upload Control元件上傳檔案

  26. 10-7-1 HTML的檔案欄位標籤 • 檔案欄位提供瀏覽程式選擇檔案的功能,可以檢視瀏覽端的檔案清單,其基本語法如下所示: <input type="file" name="field_name"> • 表單<form>標籤的屬性需要設定enctype,如下所示: <form action="filename.asp" method="post" enctype="multipart/form-data">

  27. 10-7-2 安裝Dundas Upload Control檔案上傳元件 • Dundas Upload Control元件是一個免費且完整測試的MTS元件,支援Windows 95/98/ME/Windows NT/2000作業系統,可以使用在IIS或PWS的Web伺服器,只需瀏覽程式相容RFC 1867,即Netscape 3.0版和Microsoft Internet Explorer 4.0以上版本,就可以使用ASP程式上傳檔案。 • Dundas Upload Control元件目前的版本是2.0版,其安裝程式檔案是【AspUpload.exe】,只需執行此程式檔案,就可以在IIS或PWS的電腦安裝Dundas Upload Control 元件。

  28. 10-7-3 使用Dundas Upload Control元件上傳檔案-1 • 在ASP程式使用Dundas Upload Control元件上傳檔案十分容易,只需建立上傳檔案的表單,然後在後端處理的ASP程式建立Upload物件,如下所示: Set objUpload = Server.CreateObject("Dundas.Upload.2") • 上述程式碼在建立好物件後,可以設定屬性來限制上傳檔案數和尺寸。

  29. 10-7-3 使用Dundas Upload Control元件上傳檔案-2

  30. 10-7-3 使用Dundas Upload Control元件上傳檔案-3 • Dundas Upload Control元件上傳的檔案可能不只一個,Files資料集合可以取得所有上傳檔案的資訊,使用For Next迴路取得資訊,其程式碼如下所示: For Each objFile in objUpload.Files Response.Write(objFile.TagName & "= " & _ objFile.Path & " (" & objFile.Size &")<br>") Next • 上述迴路取出上傳檔案的資訊,請注意!Dundas Upload Control元件需要在執行Save方法後,才能使用Files資料集合取得上傳檔案的資訊。

More Related