ASP Response 对象用于从服务器向用户发送输出的结果。

实例

使用 ASP 写文本
本例演示如何使用 ASP 来写文本。
<html>
<body>

<%
response.write("Hello World!")
%>

</body>
</html>

在 ASP 中使用 HTML 标签格式化文本
本例演示如何使用 ASP 将文本和 HTML 标签结合起来。
<html>
<body>
<%
response.write("<h2>您可以使用 HTML 标签来格式化文本</h2>")
%>

<%
response.write("<p style='color:#0000ff'>这段文本的样式是通过 style 属性添加的。</p>")
%>
</body>
</html>

将用户重定向至不同的 URL
本例演示如何将用户重定向至另一个的 URL。
<%
if Request.Form("select")<>"" then
       Response.Redirect(Request.Form("select"))
end if
%>   

<html>
<body>

<form action="/example/aspe/demo_aspe_redirect.asp" method="post">

<input type="radio" name="select" 
value="/example/aspe/demo_aspe_server.asp">
服务器实例<br>

<input type="radio" name="select" 
value="/example/aspe/demo_aspe_text.asp">
文本实例<br><br>
<input type="submit" value="跳转!">

</form>

</body>
</html> 

显示随机的链接
本例演示一个超级链接,当您每次载入页面时,它将显示两个链接中的其中一个。
<html>
<body>

<%
randomize()
r=rnd()
if r>0.5 then
  response.write("<a href='http://www.w3school.com.cn'>W3School.com.cn!</a>")
else
  response.write("<a href='http://www.news.cn'>news.cn!</a>")
end if
%>

<p>
本例演示一个链接,每当您加载本页时,就会显示两个链接之一:W3School.com.cn! 或 news.cn!各占百分之五十的几率。
</p>

</body>
</html>
控制缓存
本例演示如何控制缓存。
<%
Response.Buffer=true
%>
<html>
<body>
<p>
当您的 response 缓存清空时,这段文本就会发送到浏览器。
</p>
<%
Response.Flush
%>
</body>
</html>

清空缓存
本例演示如何清空缓存。
<%
Response.Buffer=true
%>
<html>
<body>
<p>这是我希望发送给用户的文本。</p>
<p>不,我改变主意了。我希望清除这些文本。</p>
<%
Response.Clear
%>
</body>
</html>

在处理过程中终止脚本并返回结果
本例演示如何在处理过程中中断脚本的运行。
<html>
<body>
<p>我正在写文本。这些文本不会被<br>
<%
Response.End
%>
完全发送。这时候已经不能输出任何文本了!</p>
</body>
</html>

设置在页面失效前把页面在浏览器中缓存多少分钟
本例演示如何规定页面在失效前在浏览器中的缓存时间。
<%Response.Expires=-1%>
<html>
<body>
<p>每当被访问,本页都会被刷新!</p>
</body>
</html>

设置页面缓存在浏览器中的失效日期或时间
本例演示如何规定页面在浏览器中的缓存时间日期或时间
<%
Response.ExpiresAbsolute=#May 05,2001 05:30:30#
%>
<html>
<body>
<p>本页面的缓存会在该日期失效:05, 2001 05:30:30!</p>
</body>
</html>

检查用户是否仍然与服务器相连
本例演示如何检查用户是否已与服务器断开。
<html>
<body>

<%
If Response.IsClientConnected=true then
Response.Write("用户仍然保持连接。")
else
Response.Write("用户未连接。")
end if
%>

</body>
</html>

设置内容类型
本例演示如何规定内容的类型。
<%
Response.ContentType="text/html"
%>
<html>
<body>

<p>This is some text.</p>

</body>
</html>

设置字符集
本例演示如何规定字符集的名称。
<%
Response.Charset="ISO8859-1"
%>
<html>
<body>

<p>This is some text</p>

</body>
</html>

Response 对象

ASP Response 对象用于从服务器向用户发送输出的结果。它的集合、属性和方法如下:

集合

集合
描述

Cookies
设置 cookie 的值。假如不存在,就创建 cookie ,然后设置指定的值。

属性

属性
描述

Buffer
规定是否缓存页面的输出。

CacheControl
设置代理服务器是否可以缓存由 ASP 产生的输出。

Charset
将字符集的名称追加到 Response 对象中的 content-type 报头。

ContentType
设置 Response 对象的 HTTP 内容类型。

Expires
设置页面在失效前的浏览器缓存时间(分钟)。

ExpiresAbsolute
设置浏览器上页面缓存失效的日期和时间。

IsClientConnected
指示客户端是否已从服务器断开。

Pics
向 response 报头的 PICS 标志追加值。

Status
规定由服务器返回的状态行的值。

方法

方法
描述

AddHeader
向 HTTP 响应添加新的 HTTP 报头和值。

AppendToLog
向服务器记录项目(server log entry)的末端添加字符串。

BinaryWrite
在没有任何字符转换的情况下直接向输出写数据。

Clear
清除已缓存的 HTML 输出。

End
停止处理脚本,并返回当前的结果。

Flush
立即发送已缓存的 HTML 输出。

Redirect
把用户重定向到另一个 URL。

Write
向输出写指定的字符串。

posted on 2010-01-18 22:56  oKmAn.Org  阅读(253)  评论(0编辑  收藏  举报