1 / 20

動態網頁設計 - ASP & 資料庫應用

動態網頁設計 - ASP & 資料庫應用. 講師:梁家豪 E-Mail: u8855043@ccu.edu.tw. VBScript 簡介. 迴圈是具有重複執行能力的程式結構 For – Next For 計數變數 = 起始值 To 終止值 Step 步進值 敘述區塊 Next Ex. 計算1加到100的值 For I = 1 to 100 I = I + 1 Next. VBScript 簡介. While – Wend: 當條件式成立時 執行 While 條件式 敘述區塊 Wend

Download Presentation

動態網頁設計 - 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 & 資料庫應用 講師:梁家豪 E-Mail: u8855043@ccu.edu.tw

  2. VBScript簡介 • 迴圈是具有重複執行能力的程式結構 • For – Next For 計數變數 = 起始值 To 終止值 Step 步進值 敘述區塊 Next • Ex. 計算1加到100的值 For I = 1 to 100 I = I + 1 Next

  3. VBScript簡介 • While – Wend:當條件式成立時執行 While 條件式 敘述區塊 Wend • Do – Loop – Until:當條件式成立時結束 Do 敘述區塊 Loop Until 條件式

  4. VBScript簡介 • Exit Do,Exit For – 是直接脫離回圈,不再執行 • 巢狀迴圈 – 迴圈裡面也可以有迴圈,這種情況形即稱為巢狀迴圈 • 九九乘表 For I = 1 to 9 For J = 1 to 9 Response.write I &”*”& J &”=“& I*J next next

  5. VBScript簡介 • 陣列(Array),其主要功能與變數相同,是用來存放資料的,不同的地方在於,一個變數只能存放一項資料,而陣列可用來儲存連續的多項資料。 • 陣列需宣告使用:Dim 陣列名稱(最後元素數) Dim A(4)

  6. VBScript簡介 • 改變陣列大小 – ReDim Dim A(5) ReDimA(6) ‘錯誤 ReDim B(5) ReDimB(6) ‘改變成功 • ReDim Preserve陣列名稱(N) • 二維與多維陣列 • Dim 陣列名稱(列,行) Ex. Dim A(1,3)

  7. ASP 內建物件 • Response • 可用來傳輸資料至瀏覽器(Client) • Request • 可讀取瀏覽器的資訊和傳送的資料 • Server • 可提供Server的相關資訊 • Application • 可用來記錄不同網頁的共用資訊 • Session • 可用來記錄特定使用者的資訊

  8. Response 物件 • 輸出 • Response.write • 轉移網頁 • Response.redirect • 結束輸出 • Response.end • 輸出的形態 • Response.ContentType

  9. Response 物件 <html> <body> 中原標準時間: <% Response.write NOW %> </body> </html> <html> <body> 中原標準時間:2001/12/3 上午 08:26:07 </body> </html> 若該ASP指令只有一行Respons.write 時,亦可以寫成 <%=NOW%>

  10. Response 物件 • Response.redirect 網址 • Ex. Response.redirect “a.htm” • Ex. Response.redirect “http://www.ccu.edu.tw” • 注意!Redirect方法只能夠在還沒有任何資料出到瀏覽器之前,才能呼叫,否則會產生錯誤訊息

  11. Response 物件 • Response.End – 終止ASP程式編譯動作,並停止輸出資料流至Client If Error = True then Response.write “發生不明錯誤” Response.End End If • Response.ContentType – 資料流形態 Response.ContentType = “text/html”

  12. 表單介紹 • Form – 表單主體 <form action=“執行程式.asp” method = “GET|POST”> 表單內容 </form> • Get • 立刻傳送,執行效能高,可傳送資料有2K的限制 • Post • 等待Server讀取,可傳送大量資料

  13. 表單介紹 • 文字方塊 < INPUT TYPE=“TEXT” NAME=“name” [SIZE=n] [MAXLENGTH=n] [VALUE=DefaultValue]> • Name – 名稱 • Size – 大小 • MaxLength = 予許輸入的最長長度 • Ex. <input type=“text” name=“school” size=“10” value=“ccu”>

  14. 表單介紹 • 密碼方塊 < INPUT TYPE=“PASSWORD” NAME=“name” [SIZE=n] [MAXLENGTH=n] > • 文字區塊 < TEXTAREA ROWS=n COLS=n NAME=“name” > [Default text] </TEXTAREA> • Rows – 寬度 • Cols – 高度 • Default Text – 預設文字

  15. 表單介紹 • 下拉式選單 < SELECT NAME=“name” [SIZE=1] >   < OPTION [VALUE=“value-1”] > select item-1 </OPTION>   < OPTION [VALUE=“value-2”] > select item-2 </OPTION> < OPTION [VALUE=“value-3”] > select item-n </OPTION> < /SELECT> • Ex. 居住地 < SELECT NAME=“country” >   < OPTION VALUE=“台灣” selected> 台灣 </OPTION>   < OPTION VALUE=“美國”> 美國 </OPTION>   < OPTION VALUE=“英國”> 英國 </OPTION> < /SELECT>

  16. 表單介紹 • 稽核方塊:能一次選取多個 < INPUT TYPE=“CHECKBOX” NAME=“name” [VALUE=“value-1”] [checked]> • Ex.興趣 <input type=“checkbox” name=“interest” value=“PC”>電腦 <input type=“checkbox” name=“interest” value=“PL”>玩樂 • 圈選按鈕:一次只能選擇一個 < INPUT TYPE=“RADIO” NAME=“name” [VALUE=“value-1”] [checked]> • Ex. 性別 <input type=“radio” value=“M” checked>男 <input type=“radio” value=“F”>女

  17. 表單介紹 • 一般按鈕 <input type=“BUTTON” name=“name” value=“value”> • 送出按鈕 <input type=“SUBMIT” value=“送出”> • 重設按鈕 <input type=“RESET” value=“清除重設”> • 隱藏元件 <input type=“HIDDEN” name=“name” value=“value”>

  18. Request 物件 • Request(“變數名稱”) • Ex. <input type=“text” name=“school”> 取得上述表單輸入的值 Request(“school”) • 網址亦可以傳送變數,不需透過表單(GET) • Ex. http://127.0.0.1/test.asp?school=ccu • Request(“school”) ‘其值為ccu

  19. Request 物件 • 稽核方塊 – 一次收到多個資料的處理 <input type=“checkbox” name=“interest” value=“PC”>電腦 <input type=“checkbox” name=“interest” value=“book”>看書 <input type=“checkbox” name=“interest” value=“music”>音樂 • 當使用者選取多個使用Request(“interest”)讀到的值會是 電腦, 看書, 音樂字串之間會以「逗點空格」格開 • 若希望收到的資料能分開列出,要使用以下方法 Interest = Split( Request(“interest”), “, “) For I = 0 to UBOUND(Interest) Response.write Interest(I) Next

  20. Request 物件 • 處理文字區塊送來的資料 <textarea name=“recommend”>……</textarea> • <%=Request(“recommend”)%> ‘並無法顯示換行的符號 • 若需要顯示,則需經以下程式轉換 <%=Replace(Request(“recommend”), vbCrLf, “<br>”)%> • 處理文字方塊送來資料的空白 • LTrim(字串變數) – 清除左邊空白 • RTrim(字串變數) – 清除右邊空白 • Trim(字串變數) – 清除左右兩側空白

More Related