基礎教程|基礎教程 一、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
<style type="text/css">
<!--
.input {background-color: #FFFFFF; border-bottom: black 1px solid;border-left: black 1px solid; border-right: black 1px solid;border-top: black 1px solid; color: #000000;font-family: Georgia; font-size: 9pt;color: midnightblue;}
a:link {color: #1B629C; text-decoration: none}
a:hover {color: #FF6600; text-decoration: underline}
a:visited {text-decoration: none}
-->
</style>
<center>
<form name="course" action="request_form.asp" method="post">
User_id:<input type="text" name="user_id" maxlength="20" class="input"><br><br>
User_name:<input type="text" name="user_name" maxlength="30" class="input">
</form>
<br><br>
<a href="javascript:document.course.submit();"> 提 交 </a>
</center>
request_form.asp
<%
'擷取使用者輸入,並存入變數
user_id=request.form("user_id")
user_name=request.form("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
%>
注意:form的action的指向,request_form.asp和request_url.asp在原始碼上的區別?
2. Response:
定義:用來向瀏覽器回傳資訊,可用此對象從指令碼向瀏覽器發送輸出。
集:
Cookies:在瀏覽器中加入一個cookie
方法:
End:結束指令碼的處理
Redirect:將瀏覽器引導至新頁面
Write:向瀏覽器發送一個字
[1] [2] [3] [4] [5] 下一頁