Asp深度揭密(上)
來源:互聯網
上載者:User
一、Asp基本知識
1.Asp是Active Server Pages的簡稱,是解釋型的指令碼語言環境;
2.Asp的運行需要Windows作業系統,9x下需要安裝PWS;而NT/2000/XP則需要安裝Internet Information Server(簡稱IIS);
3.Asp和JSP的指令碼標籤是“<%%>”,PHP的則可以設定為多種;
4.Asp的注釋符號是“'”;
5.使用附加組件,可以擴充Asp的功能。
例子:
HelloWorld_1.asp
<%="Hello,world"%>
效果:
Hello,world
HelloWorld_2.asp
<%
for i=1 to 10
response.write "Hello,world"
next
%>
效果:
Hello,world
Hello,world
Hello,world
Hello,world
Hello,world
Hello,world
Hello,world
Hello,world
Hello,world
Hello,world
注意:Asp不區分大小寫;變數無需定義也可使用,轉換方便;語法檢查很松。
二、Asp內建對象的使用:
可以使用下面的任何ASP內建對象,而不必在ASP指令碼中特別聲明。
1. Request:
定義:可用來訪問從瀏覽器發送到伺服器的請求資訊,可用此對象讀取已輸入HTML表單的資訊。
集:
Cookies:含有瀏覽器cookies的值
Form:含有HTML表單域中的值
QueryString:含有查詢字串的值
ServerVariables:含有頭和環境變數中的值
例子:
request_url.asp
<%
'擷取使用者輸入,並存入變數
user_id=request.querystring("user_id")
user_name=request.querystring("user_name")
'判斷使用者輸入是否正確
if user_id="" then
response.write "User_id is null,please check it"
response.end
end if
if user_name="" then
response.write "User_name is null,please check it"
response.end
end if
'列印變數
response.write user_id&"<br>"
response.write user_name
%>
效果:
當訪問http://10.1.43.238/course/request_url.asp?user_name=j時:
User_id is null,please check it
當訪問http://10.1.43.238/course/request_url.asp?user_name=j&user_id=my_id時:
my_id
j
思考:變數是如何在URL中傳遞和被Asp頁面擷取的?
request_form.htm