ASP Response 对象用于从服务器向用户发送输出的结果。
ASP Response 对象用于从服务器向用户发送输出的结果。它的集合、属性和方法描述如下:
集合 | 描述 |
---|---|
Cookies | 设置 cookie 的值。如果 cookie 不存在,则创建 cookie ,并设置指定的值。 |
属性 | 描述 |
---|---|
Buffer | 规定是否缓冲页面的输出。 |
CacheControl | 设置代理服务器是否可以缓存由 ASP 产生的输出。 |
Charset | 将字符集的名称追加到 Response 对象中的 content-type 报头。 |
ContentType | 设置 Response 对象的 HTTP 内容类型。 |
Expires | 设置页面在失效前的浏览器缓存时间(分钟)。 |
ExpiresAbsolute | 设置浏览器上页面缓存失效的日期和时间。 |
IsClientConnected | 指示客户端是否已从服务器断开。 |
Pics | 向 response 报头的 PICS 标签追加值。 |
Status | 规定由服务器返回的状态行的值。 |
方法 | 描述 |
---|---|
AddHeader | 向 HTTP 响应添加新的 HTTP 报头和值。 |
AppendToLog | 向服务器日志条目的末端添加字符串。 |
BinaryWrite | 在没有任何字符转换的情况下直接向输出写数据。 |
Clear | 清除已缓冲的 HTML 输出。 |
End | 停止处理脚本,并返回当前的结果。 |
Flush | 立即发送已缓冲的 HTML 输出。 |
Redirect | 把用户重定向到一个不同的 URL。 |
Write | 向输出写指定的字符串。 |
使用 ASP 写文本
本例演示如何使用 ASP 来写文本。
- <!DOCTYPE html>
- <html>
- <body>
- <%
- response.write("Hello World!")
- %>
- </body>
- </html>
- Hello World!
在 ASP 中使用 HTML 标签格式化文本
本例演示如何使用 ASP 将文本和 HTML 标签结合起来。
- <!DOCTYPE html>
- <html>
- <body>
- <%
- response.write("<h2>You can use HTML tags to format the text!</h2>")
- %>
- <%
- response.write("<p style='color:#0000ff'>This text is styled with the style attribute!</p>")
- %>
- </body>
- </html>
This text is styled with the style attribute!
将用户重定向至一个不同的 URL
本例演示如何将用户重定向至一个不同的 URL。
- <%
- if Request.Form("select")<>"" then
- Response.Redirect(Request.Form("select"))
- end if
- %>
- <!DOCTYPE html>
- <html>
- <body>
- <form action="demo_redirect.asp" method="post">
- <input type="radio" name="select"
- value="demo_server.asp">
- Server Example<br>
- <input type="radio" name="select"
- value="demo_text.asp">
- Text Example<br><br>
- <input type="submit" value="Go!">
- </form>
- </body>
- </html>
显示随机的链接
本例演示如何创建一个随机的链接。
- <!DOCTYPE html>
- <html>
- <body>
- <%
- randomize()
- r=rnd()
- if r>0.5 then
- response.write("<a href='http://www.shouce.ren'>jianzhan.cc!</a>")
- else
- response.write("<a href='http://www.refsnesdata.no'>Refsnesdata.no!</a>")
- end if
- %>
- <p>
- This example demonstrates a link, each time you load the page, it will display
- one of two links: jianzhan.cc! OR Refsnesdata.no! There is a 50% chance for
- each of them.
- </p>
- </body>
- </html>
控制缓冲区
本例演示如何控制缓冲区。
- <%
- Response.Buffer=true
- %>
- <!DOCTYPE html>
- <html>
- <body>
- <p>
- This text will be sent to your browser when my response buffer is flushed.
- </p>
- <%
- Response.Flush
- %>
- </body>
- </html>
清空缓冲区
本例演示如何清空缓冲区。
- <%
- Response.Buffer=true
- %>
- <!DOCTYPE html>
- <html>
- <body>
- <p>This is some text I want to send to the user.</p>
- <p>No, I changed my mind. I want to clear the text.</p>
- <%
- Response.Clear
- %>
- </body>
- </html>
在处理过程中终止脚本并返回结果
本例演示如何在处理过程中终止脚本。
- <!DOCTYPE html>
- <html>
- <body>
- <p>I am writing some text. This text will never be<br>
- <%
- Response.End
- %>
- finished! It's too late to write more!</p>
- </body>
- </html>
设置页面在失效前在浏览器中缓存时间
本例演示如何规定页面在失效前在浏览器中的缓存时间。
- <%Response.Expires=-1%>
- <!DOCTYPE html>
- <html>
- <body>
- <p>This page will be refreshed with each access!</p>
- </body>
- </html>
设置页面缓存在浏览器中的失效日期或时间
本例演示如何规定页面缓存在浏览器中的失效时间日期或时间。
- <%Response.Expires=-1%>
- <!DOCTYPE html>
- <html>
- <body>
- <p>This page will be refreshed with each access!</p>
- </body>
- </html>
检查用户是否仍然与服务器连接
本例演示如何检查用户是否已与服务器断开。
- <!DOCTYPE html>
- <html>
- <body>
- <%
- If Response.IsClientConnected=true then
- Response.Write("The user is still connected!")
- else
- Response.Write("The user is not connected!")
- end if
- %>
- </body>
- </html>
设置内容类型
本例演示如何规定内容的类型。
- <%
- Response.ContentType="text/html"
- %>
- <!DOCTYPE html>
- <html>
- <body>
- <p>This is some text</p>
- </body>
- </html>
设置字符集名称
本例演示如何规定字符集的名称。
- <%
- Response.Charset="ISO8859-1"
- %>
- <!DOCTYPE html>
- <html>
- <body>
- <p>This is some text</p>
- </body>
- </html>