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属性,这个可就不一定了哦。
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属性,这个可就不一定了哦。
输入您的搜索字词 提交搜索表单 | |||
|
相关文章推荐
- 2.关于结构体以及结构体数组作为函数入口参数的方法(学习笔记)
- ASP.NET AJAX 以及AJAXPRO使用客户端调用服务器端的方法--初学者学习
- ASP.NET 3.5核心编程学习笔记(58):利用页面方法来进行远程调用
- java学习笔记5——对象以及包,类和方法
- 学习笔记---将Asp.Net网站发布到IIS的四种方法及注意事项
- ASP.NET 3.5核心编程学习笔记(30):HttpResponse对象
- [ASP.NET学习笔记之四]数据集的使用方法和技巧
- 黑马程序员-面向对象的理解以及Objective-C方法和对象分配内存的学习笔记
- 黑马程序员之ASP.NET学习笔记: Http方法:Get请求与Post请求的区别
- [ASP.NET学习笔记之四]数据集的使用方法和技巧
- ASP.Net MVC开发基础学习笔记:二、HtmlHelper与扩展方法
- Dynamic CRM 2013学习笔记(二十三)CRM JS智能提示(CRM 相关的方法、属性以及页面字段),及发布前调试
- 安卓学习笔记---Fragmnet使用之add,show,hide,remove以及replace方法
- js学习笔记 - sort()方法的用法,参数以及排序原理
- 【原创】Asp.net MVC 学习笔记之-为什么使用Html.TextBox方法会出现异常?
- 学习笔记---Equal()方法、ReferenceEqual()方法以及运算符==的区别
- 黑马程序员之 ASP.NET学习笔记:GridView控件的常用属性及方法
- ASP生成静态网页,学习CASE的用法,以及“权限”的一种控制方法
- OK6410 Linux开发环境搭建--编译以及ubuntu的使用方法学习笔记
- 黑马程序员-OC学习笔记-点方法、成员变量作用域以及set方法和get方法@property的综合题