在ASP程序设计中在使用Response对象
在這里我們將關(guān)注其最常用的一些功能。也就是在程序設(shè)計(jì)中經(jīng)常要用到的一些功能,具體如下:
(1).response.write 發(fā)送信息到瀏覽器
(2). response.end 有效地中止代碼
(3).response.redirect 頁面重定向
如何用response.write發(fā)送信息到瀏覽器?
在下面的response.asp就是一個(gè)向客戶端發(fā)送信息的程序,在程序中用到了一個(gè)內(nèi)建功能--dateadd,對(duì)于這個(gè)功能可以參閱以下相關(guān)文檔:
http://help.activeserverpages.com/iishelp/VBScript/htm/vbs90.htm.
Response.asp程序源代碼:
| <html><head><title>response.asp </title></head> <body color = "#FFFFFF" ><p> <%when = now ( ) ???? tommorow = dateadd ( "d" , 1 , when ) ???? twoweekslater = dateadd ( "ww" , 2 , when ) ???? fourteenweekdayslater = dateadd ( "w" , 14 , when ) ???? monthlater = dateadd ( "m" , 1 , when ) ???? sixminuteslater = dateadd ( "n" , 6 , when ) ???? sixhourslater = dateadd ( "h" , 6 , when ) ???? fortysecslater = dateadd ( "s" , 40 , when ) ???? response.write "現(xiàn)在時(shí)間:<b>" & when & "</b> <br>" ???? response.write "明天此時(shí): <b>" & tommorow & "</b> <br>" ???? response.write "一月以后此時(shí): <b> " & monthlater & " </b> <br>" %> ???? 從現(xiàn)在以后6秒鐘:<b> <%= sixminuteslater %> </b> <br> ???? 從現(xiàn)在以后6小時(shí)是:<b> <%= sixhourslater %> </b> <br> ???? 從現(xiàn)在以后40秒是: <b> <%= fortysecslater %> </b> <br> ?</body> </html> |
執(zhí)行以后的界面如下:
response.end 是如何有效地中止代碼?
下面是用response.end終止一個(gè)頁面操作的源程序end.asp和執(zhí)行后的運(yùn)行界面:
| end.asp: <title>end.asp </title> <body color = "#FFFFFF" > <%when = now ( ) ??????tommorow = dateadd ( "d" , 1 , when ) ????? twoweekslater = dateadd ( "w" , 2 , when ) ????? monthlater = dateadd ( "m" , 1 , when ) ????? sixminuteslater = dateadd ( "n" , 6 , when ) ????? sixhourslater = dateadd( "h" , 6 , when ) ????? response.write "現(xiàn)在時(shí)間: <b>" & when & " </b> <br> " ????? response.write "從現(xiàn)在以后一個(gè)月時(shí)間: <b>" & monthlater & "</b> <br>" ????? response.end ????? response.write "從現(xiàn)在以后二周時(shí)間: <b>" & twoweekslater & "</b><br>" %>?? ????? 從現(xiàn)在以后6秒時(shí)間: <b> <%= sixminuteslater %> </b> <br> ????? 從現(xiàn)在以后6個(gè)小時(shí):<b> <%= sixhourslater %> </b> <br> |
運(yùn)行此程序,則執(zhí)行界面如下:
圖02:end.asp程序執(zhí)行界面
在end.asp程序中可見多了一個(gè)response.end語句:如果沒有這個(gè)語句,則程序執(zhí)行后的界面如下:
圖03:程序中屏蔽respons.end語句的執(zhí)行界面
由此可見Response.end是如何有效中止代碼執(zhí)行的了。
Response.redirect實(shí)現(xiàn)頁面重定向
用 Redirect 方法可將瀏覽器重定向到另一個(gè) URL,而不是將內(nèi)容發(fā)送給用戶。例如,如果您想確認(rèn)用戶是否已從主頁進(jìn)入了您的應(yīng)用程序,以便能收到一個(gè)客戶 ID,則可以檢驗(yàn)他們是否有客戶 ID 號(hào);如果沒有,就可以將其重定向到主頁。以下就是具體例子:
<%If Session("CustomerID") = 0 Then Response.Redirect "homepage.asp" End If%>
除非緩沖區(qū)已經(jīng)打開,否則,在任何內(nèi)容或標(biāo)題返回給瀏覽器之前,您必須重定向?yàn)g覽器。將 Response.Redirect 語句放在頁的頂部和<HTML> 標(biāo)記之前可確保沒有任何內(nèi)容返回給瀏覽器。如果在返回給瀏覽器的內(nèi)容或標(biāo)題后使用 Response.Redirect,將看到一個(gè)錯(cuò)誤信息。
如果在頁的中間使用 Response.Redirect,請(qǐng)將其與 Response.Buffer 屬性一起使用,這是因?yàn)樵谀J(rèn)情況下,Web 服務(wù)器返回 HTML 和在處理 ASP 頁時(shí)的腳本處理結(jié)果。但是,您可以設(shè)置 Response 對(duì)象的 Buffer 屬性以便在向用戶發(fā)送任何內(nèi)容之前,先處理頁上的所有的服務(wù)器腳本命令。
可以使用緩沖技術(shù)來確定在頁處理過程中的某個(gè)點(diǎn),而您并不想將該點(diǎn)之前的內(nèi)容發(fā)送給用戶。也可以用 Response 對(duì)象的 Redirect 方法將用戶重定向到另一頁,或者用 Response 對(duì)象的 Clear 方法清除緩沖區(qū)并將不同的內(nèi)容發(fā)送給用戶。下面的例子使用了以上兩種方法。
例子一:
| <% '下一句程序必須放在程序在<HTML> 標(biāo)識(shí)符前Response.Buffer = True %><html><body>... 例子二: <%If Request ("FName") = "" Then ???? Response.Clear ???? Response.Redirect ".. /test.html" Else ???? Response.Write Request("FName") End If%></body></html> |
以上就是Response對(duì)象的在程序中經(jīng)常用到的功能。
Server對(duì)象有那些屬性方法以及怎樣使用
Server對(duì)象提供對(duì)服務(wù)器訪問的方法和屬性。其中大多數(shù)方法和屬性是作為實(shí)用程序的功能提供的。
Server對(duì)象有哪些基本屬性和方法?
(1).語法:
Server.property|method
(2).屬性(property)
Server對(duì)象只有一個(gè)屬性:ScriptTimeout 程序能夠運(yùn)行的最大時(shí)間
(3).方法(Methods)
CreateObject 建立一個(gè)對(duì)象實(shí)例.
Execute 執(zhí)行一個(gè)asp文件
GetLastError 返回一個(gè)錯(cuò)誤代碼
HTMLEncode 對(duì)指定的HTML代碼進(jìn)行轉(zhuǎn)換.
MapPath 將一個(gè)相對(duì)路徑轉(zhuǎn)化為一個(gè)絕對(duì)路徑.
Transfer 將當(dāng)前的所有狀態(tài)信息發(fā)送給另一個(gè)asp文件
URLEncode 以URL形式轉(zhuǎn)化指定的代碼,包括空格
轉(zhuǎn)載于:https://www.cnblogs.com/QDuck/archive/2005/04/14/137523.html
總結(jié)
以上是生活随笔為你收集整理的在ASP程序设计中在使用Response对象的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [导入]在IE耗时操作中加入进度条或进度
- 下一篇: 拉肚子,不能吃东西的痛苦