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

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属性,这个可就不一定了哦。

 

 

Google
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值