1. 現(xiàn)在的日期時(shí)間命令是 <%=now%> 即可
2.ASP取得表格(from)數(shù)據(jù)輸入的方法,是使用一個(gè)內(nèi)置的對(duì)象(object)—Requect, 它以get,post而異。
3.若要自己用VB或其它語(yǔ)言編寫(xiě),.dll文件供ASP使用需將DLL文件注冊(cè)方可:DOS下 輸入 regsbr32 *.dll
4.顯示五個(gè)重復(fù)的句子,字體越來(lái)越大 <% for i=1 to 5 %> <font size=<% =i %> color=#00ffff> 快速ASP </font> <br> <% next %>
5.傳送字符串到用戶(hù)端 response.write string 如:<% response.write "Welcome" %>
6.鏈接到指定的URL地址 response.redirect url 如: <% response.redirect "homepage.asp" %>
*但是如果此.ASP的文件內(nèi)容已經(jīng)傳送到用戶(hù)斷,則再用redirect時(shí)會(huì)發(fā)生錯(cuò)誤。
7.其他語(yǔ)言與ASP的結(jié)合: 如:早上顯示早安,下午顯示你好 <% if time>+#12:00:00 AM# and time<#12:00:00 PM # then greeting="早安!" else greeting="你好!" end if %> <%=greeting %>
8.<script>標(biāo)記在ASP中的應(yīng)用 例:
<html> <body> <% call function1 %> </body> </html> <script runat=server language=javascript> function function1() { ... } </script>
9.#include 包括其它文件 <!--#include virtual|file="filename"--> virtual指虛擬的文件地址。 file 代表絕對(duì)的文件地址。 如: <!--#include virtual="/booksamp/test.asp"--> <!--#include file="/test/test.asp"-->
而且可以層層嵌套。另外#include 不能在<%--%>之內(nèi)
10.ASP取得表格輸入數(shù)據(jù)的方法 :GET POST 一.get:用戶(hù)端將數(shù)據(jù)加到URL后,格式為”?字段1=輸入數(shù)據(jù)1&字段2=輸入數(shù)據(jù)2&...", 再將其送到服務(wù)器。 如: action為www.abc.com, 字段Name輸入數(shù)據(jù)為jack,字段age的數(shù)據(jù)為15,則用get方法為 http://www.abc.com?Name=jack&Age=15
二.post:用戶(hù)端用http信息數(shù)據(jù)傳送到服務(wù)器 ASP中: get:使用“輸入數(shù)據(jù)= Request.QueryString("字段名")",將附加于URL的數(shù)據(jù)取出。 post:使用“輸入數(shù)據(jù)=Request.Forml"(字段名")",讀取HTTP信息數(shù)據(jù)字段。 * 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的內(nèi)容 <html><body> <% =request.querystring("input1") %> hi, your character is <%= request.querystring("input2") %> </body></html> 11.request.From 語(yǔ)法: request.From(name)[(index)|.count] name:字段名 index:當(dāng)同一字段輸入多個(gè)值時(shí),指針值index指定要讀取同一字段的那一個(gè)值,范圍由1到 request.From(name).count count:由request.From(name).count可知name字段輸入幾個(gè)值,若無(wú)此name字段,count為0
如下例: <% forI=1 to request.fron("input1").count response.write request.From("input1")(I)&"<br>" next %> 若input1有兩個(gè)值則都顯示出 *若未采用index指定讀取哪個(gè).可用 〈% for each item request.From("input")) repomse.write item &"<br>" next %> 也可用" for each x in tewuest.From"重復(fù)取得所有字段的輸入值。
<% for each x in request.Form %> request.From (<%=x%)=<%=request.Form (x)%> <br> <% next %>
12. 獲取客戶(hù)端TCP/IP端口的方法: 如: tcp/ip port is <%=request("server_port")%> 使用server_port可以得到接收HTTP request的連接port信息
13. 通過(guò)HTTP_ACCEPT_LANGUAGE的HTTP表頭信息,可以得到用戶(hù)端的使用語(yǔ)言 環(huán)境. 以下例子判斷用戶(hù)端的語(yǔ)言環(huán)境,給出不同的頁(yè)面. <% language=request.servervariables("HTTP_ACCEPT_LANGUAGE") if language="en" then %> <!--#include file="english.asp"> <% else %> <!--#include file="china.asp"> <% end if%>
14.主頁(yè)保留的期限 如果用戶(hù)端瀏覽器在一個(gè)主頁(yè)保留的期限內(nèi),再度瀏覽此主頁(yè),則原在用 戶(hù)端硬盤(pán)上的主頁(yè)內(nèi)容將被顯示. response.expires[=number] 其中NUMBER為記錄數(shù)據(jù)盒(PAGE BOX)的保留期限,單位是分鐘. 或: response.expiresabsolute[=[date][time]] 如:設(shè)定一個(gè)主頁(yè)保留期到某個(gè)日子.
15.連接到指定的URL地址 如:你希望確認(rèn)用戶(hù)已經(jīng)看過(guò)INDEX.HTM,則可以檢查是否已經(jīng)看過(guò),如 尚未確認(rèn),則自動(dòng)連接到首頁(yè) <% if not session("BEEN_to_home_page") then response.redirect "index.asp" end if %>
16.判斷是回到本頁(yè)還是第一次進(jìn)入 <% if user_has_been_here_before then response.write "<h3 align=center> Welcome Back again" else response.write "Welcome!" end if %>
17.顯示數(shù)據(jù)庫(kù)中的圖片與超級(jí)連接
<% 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 %> </b> </td> <% next %> </tr> <% do while not rs.eof %> <tr> <% for i=0 to rs.fields.count-1 %> <td valign =top> <% if rs(i).name="image" then response.write "<img src="""&rs(i)&""" >" else if rs(i).name="url" then response.write "<a href="""&rs(i)&""">"&rs(i)&"</a>" else response.write rs(i) end if end if %> </td> <%next%> </tr> <% rs.movenext loop rs.close conn.close %> </html>
18. 用ASP取得瀏覽器信息 <% set a=server.creatobject("MSWC.BROWSERTYPE") msg="您使用的瀏覽器是:"+a.browser+"version"+a.version %> <%=msg%>
|