1.ASP取得表格輸入資料的方法:GET POST
一.get:使用者端將資料加到URL後,格式為”?欄位1=輸入資料1&欄位2=輸入資料2&...", 再將其送到伺服器。如: action為www.abc.com, 欄位Name輸入資料為jack,欄位age的資料為15,則用get方法為 http://www.abc.com?Name=jack&Age=15
二.post:使用者端用http資訊資料傳送到伺服器 ASP中: get:使用“輸入資料= Request.QueryString("欄位名")",將附加於URL的資料取出。 post:使用“輸入資料=Request.Forml"(欄位名")",讀取HTTP資訊資料欄位。 * Request.QueryString範例如:〈A hery="aspform.asp?Name=jack&Age=15"> 按此〈/A〉〈p〉 Name:<%=request.QueryString("Name")%) Age:<%=request.QeueryString("Age")%) * get 範例 ·aspturm.asp: <form action="asp1b.asp" method="get"> 姓名: <input type=text name="input1" value="Your name"> <p> 特徵: <select name="input2"> <option>cool! <option>handsome <option>warmhearted </select> <input type=submit value="ok"> </form> asp1b.asp的內容 <html><body> <% =request.querystring("input1") %> hi, your character is <%= request.querystring("input2") %>
</body></html>
2.request.From 文法: request.From(name)[(index)|.count] name:欄位名 index:當同一欄位輸入多個值時,指標值index指定要讀取同一欄位的那一個值,範圍由1到 request.From(name).count count:由request.From(name).count可知name欄位輸入幾個值,若無此name欄位,count為0
如下例: <% forI=1 to request.fron("input1").count response.write request.From("input1")(I)&"<br>" next %> 若input1有兩個值則都顯示出 *若未採用index指定讀取哪個.可用〈% for each item request.From("input")) repomse.write item &"<br>" next %> 也可用" for each x in tewuest.From"重複取得所有欄位的輸入值。
<% for each x in request.Form %> request.From (<%=x%)=<%=request.Form (x)%> <br> <% next %>
3. 擷取用戶端TCP/IP連接埠的方法: 如: tcp/ip port is <%=request("server_port")%> 使用server_port可以得到接收HTTP request的串連port資訊
4. 通過HTTP_ACCEPT_LANGUAGE的HTTP表頭資訊,可以得到使用者端的使用語言環境. 以下例子判斷使用者端的語言環境,給出不同的頁面. <% language=request.servervariables("HTTP_ACCEPT_LANGUAGE") if language="en" then %> <!--#include file="english.asp"> <% else %> <!--#include file="china.asp"> <% end if%>
5. 現在的日期時間命令是 <%=now%> 即可
6.ASP取得表格(from)資料輸入的方法,是使用一個內建的對象(object)—Requect, 它以get,post而異。
7.若要自己用VB或其它語言編寫,.dll檔案供ASP使用需將DLL檔案註冊方可:DOS下輸入 regsbr32 *.dll
8.顯示五個重複的句子,字型越來越大 <% for i=1 to 5 %> <font size=<% =i %> color=#00ffff> 快速ASP </font> <br> <% next %>
9.傳送字串到使用者端 response.write string 如:<% response.write "Welcome" %>
10.連結到指定的URL地址 response.redirect url 如: <% response.redirect "homepage.asp" %>
*但是如果此.ASP的檔案內容已經傳送到使用者斷,則再用redirect時會發生錯誤。
11.其他語言與ASP的結合:如:早上顯示早安,下午顯示你好 <% if time>+#12:00:00 AM# and time<#12:00:00 PM # then greeting="早安!" else greeting="你好!" end if %> <%=greeting %>
12.<script>標記在ASP中的應用例:
<html> <body> <% call function1 %> </body> </html> <script runat=server language=javascript> function function1() { ... } </script>
13.#include 包括其它檔案 <!--#include virtual|file="filename"--> virtual指虛擬檔案地址。 file 代表絕對的檔案地址。如: <!--#include virtual="/booksamp/test.asp"--> <!--#include file="/test/test.asp"-->
而且可以層層嵌套。另外#include 不能在<%--%>之內
14.首頁保留的期限如果使用者端瀏覽器在一個首頁保留的期限內,再度瀏覽此首頁,則原在使用者端硬碟上的首頁內容將被顯示. response.expires[=number] 其中NUMBER為記錄資料盒(PAGE BOX)的保留期限,單位是分鐘. 或: response.expiresabsolute[=[date][time]] 如:設定一個首頁保留期到某個日子.
15.串連到指定的URL地址如:你希望確認使用者已經看過INDEX.HTM,則可以檢查是否已經看過,如尚未確認,則自動連接到首頁 <% if not session("BEEN_to_home_page") then response.redirect "index.asp" end if %>
16.判斷是回到本頁還是第一次進入 <% if user_has_been_here_before then response.write "<h3 align=center> Welcome Back again" else response.write "Welcome!" end if %>
17.顯示資料庫中的圖片與超級串連
<% set conn=server.creatobject("ADODB.connection")
conn.open "myaddress"
set rs=conn.execute("select name,tel,url,image from myaddress")
%>
<p> <tabel> <tr> <% for i=0 to rs.fields.count-1 %> <td> <b> <%=rs(i).name %>