您的位置:首页 > 编程语言 > ASP

ASP学习笔记(6)--Response对象以及方法

2007-05-30 22:56 295 查看
Response是ASP的6个对象之一,表示的是server对web浏览器的回应。其包含8个方法,9个属性以及一个集合(collection) 。

8个方法如下:

AddHeader()--Response.AddHeader("my header", "my value") : add you own html header

AppendToLog()--Response.AppendToLog("my log message") : send message to server log

BinaryWrite()--Response.BinaryWrite(binary data) : write binary data such as pictures

Clear()--Response.Clear() : clear buffered response if Response.Buffer ==true

End()--Response.End() : end the response

Flush()--Response.Flush() : send buffered response if Response.Buffer ==true

Redirect()--Response.Redirect("http://www.abc.com") : redirect the browser to other page

Write()--Response.Write() : output the response to the browser

需要注意的地方是,有两种方法依赖于Response.Buffer(Clear() Flush())。并且AddHeader() 和Redirect()方法必须用在Writer()方法之前,否则会出错。看如下例子

<%@ language=javascript %>
<html>
<head>
<title>this is a test of Redirect() and Write()</title>
</head>
<body>
<form action="fortest8.asp" method="post">
<strong>do you want to redirect to google?</strong>
<select name="redirectVar">
<option>Yes, I do.</option>
<option>No, I donot.</option>
<option>Who is Google?</option>
</select>
<input type=submit value=OK>
</form>
</body>
</html>

fortest8.asp

<%@ language=javascript %>
<%
var redirectVar=new String(Request.Form("redirectVar"))
if (redirectVar=="Who is Google?")
whogoogle();
if (redirectVar=="Yes, I do.")
Response.Redirect("http://www.google.com");
if (redirectVar=="No, I donot.")
Response.Redirect("test8.asp");
if (redirectVar=="undefined")
Response.Redirect("test8.asp")
function whogoogle(){
Response.write("<html>/r")
Response.write("google is a search engine<br>/r")
Response.write(" you should try it, it is good<br>/r")
Response.write("</html>/r")
}
%>

上例中将write()方法使用在一个javascript函数中。当然了,有时候是不需要用write()也可以实现一些输出,这被成为write快捷方式。如下例:

<%@ language=javascript %>
<html>
<head>
<title>this is a test of write shortcut</title>
</head>
<% var thetime=new Date() %>
<body>
the time and date is <% =thetime %><br>
<% var sayhello="hello "
sayhello +="world"
%>
<% =sayhello %>
</body>
</html>

使用快捷方式最大的好处是我们可以输出javascript数据类型或者asp的数据类型。但是,请记住,使用快捷方式有一点需要注意,那就是每次只能输出一个数据类型。而且,我们这个例子中所有的脚本都是线性执行的,但是如果有了RUNAT属性,这个可就不一定了哦。



输入您的搜索字词 提交搜索表单
Webblog.csdn.net
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐