ASP基础教程之实例学习ASP Response 对象
来源: 录入时间:07-07-27 09:40:47
ASP Response 对象用于从服务器向用户发送输出的结果。
实例
使用ASP写文本
本例演示如何使用ASP来写文本。
<%
response.write("Hello World!")
%>
在ASP中使用HTML标签格式化文本
本例演示如何使用ASP将文本和HTML标签结合起来。
<%
response.write("
You can use HTML tags to format the text!
")%>
<%
response.write("
This text is styled with the style attribute!
")%>
将用户重定向至不同的URL
本例演示如何将用户重定向至另一个的URL。
<%
if Request.Form("select")<>"" then
Response.Redirect(Request.Form("select"))
end if
%>
显示随机的链接
本例演示一个超级链接,当您每次载入页面时,它将显示两个链接中的其中一个。
<%
randomize()
r=rnd()
if r>0.5 then
response.write("webjx.com")
else
response.write("www.webjx.com")
end if
%>
This example demonstrates a link, each time you load the page, it will display
one of two links: Webjx.com! OR www.webjx.com! There is a 50% chance for
each of them.
控制缓存
本例演示如何控制缓存。
<%
Response.Buffer=true
%>
This text will be sent to your browser when my response buffer is flushed.
<%
Response.Flush
%>
清空缓存
本例演示如何清空缓存。
<%
Response.Buffer=true
%>
This is some text I want to send to the user.
No, I changed my mind. I want to clear the text.
<%
Response.Clear
%>
在处理过程中终止脚本并返回结果
本例演示如何在处理过程中中断脚本的运行。
I am writing some text. This text will never be
<%
Response.End
%>
finished! It's too late to write more!
设置在页面失效前把页面在浏览器中缓存多少分钟
本例演示如何规定页面在失效前在浏览器中的缓存时间。
<%Response.Expires=-1%>
This page will be refreshed with each access!
设置页面缓存在浏览器中的失效日期或时间
本例演示如何规定页面在浏览器中的缓存时间日期或时间
<%
Response.ExpiresAbsolute=#May 05,2001 05:30:30#
%>
This page will expire on May 05, 2001 05:30:30!
检查用户是否仍然与服务器相连
本例演示如何检查用户是否已与服务器断开。
<%
If Response.IsClientConnected=true then
Response.Write("The user is still connected!")
else
Response.Write("The user is not connected!")
end if
%>
设置内容类型
本例演示如何规定内容的类型。
<%
Response.ContentType="text/html"
%>
This is some text
设置字符集
本例演示如何规定字符集的名称。
<%
Response.Charset="ISO8859-1"
%>
This is some text
Response 对象
ASP Response 对象用于从服务器向用户发送输出的结果。它的集、属性和方法如下:
集
| Collection | 描述 |
|---|---|
| Cookies | 设置cookie的值。假如cookie不存在,就创建cookie,然后设置指定的值。 |
属性
| Property | 描述 |
|---|---|
| Buffer | 规定是否缓冲页面的输出 |
| CacheControl | 设置代理服务器是否可以缓冲由ASP产生的输出。 |
| Charset | 将字符集的名称追加到Response对象中的content-type头部。 |
| ContentType | 设置Response对象的HTTP内容类型。 |
| Expires | 设置页面在失效前的浏览器缓存时间(分钟) |
| ExpiresAbsolute | 设置页面缓存失效的日期和时间。 |
| IsClientConnected | 指示客户端是否已从服务器断开。 |
| Pics | 向response头部的PICS标志追加值。 |
| Status | 规定由服务器返回的状态行的值。 |
方法
| Method | 描述 |
|---|---|
| AddHeader | 向HTTP response添加新的HTTP头部和值 |
| AppendToLog | 向服务器记录项目(server log entry)的末端添加字符串 |
| BinaryWrite | 在没有任何字符转换的情况下直接向输出写数据 |
| Clear | 清楚已缓冲的HTML输出 |
| End | 停止处理脚本,并返回当前的结果 |
| Flush | 立即发送已缓冲的HTML输出 |
| Redirect | 把用户重定向到另一个URL |
| Write | 向输出写指定的字符串 |
上一篇文章:
下一篇文章: