网络编程
位置:首页>> 网络编程>> Asp编程>> ASP六大对象介绍(3)

ASP六大对象介绍(3)

  发布时间:2007-09-08 12:28:00 

标签:asp对象,Application,ObjectContext,Request,Response,Server,Session

Response对象

  Response对象用于向客户端浏览器发送数据,用户可以使用该对象将服务器的数据以HTML的格式发送到用户端的浏览器,它与Request组成了一对接收、发送数据的对象,这也是实现动态的基础。下面介绍它常用的属性和方法。

 

1、Buffer属性  
  该属性用于指定页面输出时是否要用到缓冲区,默认值为False。当它为True时,直到整个Active Server Page执行结束后才会将结果输出到浏览器上。如:
<%Response.Buffer=True%>
<html>
<Head>
<title>Buffer示例</title>
</head>
<body>
<%
  for i=1 to 500
    response.write(i & "<br>")
  next
%>
</body>
</html>
  这页执行时,整个主页的所有内容会同时显示在浏览器上,这个主页会存在缓存区中直到脚本执行结束。

2、Expires属性
  该属性用于设置浏览器缓存页面的时间长度(单位为分),必须在服务器端刷新。通过如下设置:

<%Response.Expires=0%> 

  通过在ASP文件中加入这一行代码,要求每次请求是刷新页面,因为Response一收到页面就会过期。


3、Write方法
  该方法把数据发送到客户端浏览器,如:  

<%Response.write "Hello,world!"%> 


4、Redirect方法
  该方法使浏览器可以重新定位到另一个URL上,这样,当客户发出Web请求时,客户端的浏览器类型已经确定,客户被重新定位到相应的页面。如:

<html>
<head>
<title>Redirect示例</title>
</head>
<body>
<form aciton="formjump.asp" method="post">
  <select name="wheretogo">
    <option selected &#118alue="fun">Fun</option>
    <option &#118alue="news">News</option>
    <option &#118alue="sample">Sample</option>
  </select>
<input type=submit name="jump" &#118alue="Jump">
</form>
</body>
</html> 
  以上是提交的表单,下面是处理表单的文件formjump.asp:
<%response.buff=true%>
<html>
<head>
<title>Redirect示例</title>
</head>
<body>
<%
thisurl="http://www.tinyu.com/";
where=Request.form("wheretogo")
Select Case where
  case "fun"
    response.redirect thisurl & "/fun/default.asp"
  case "news"
    response.redirect thisurl & "/news/default.asp"
  case "sample"
    response.redirect thisurl & "/sample/default.asp"
End Select 
%>
</body>
<html> 


  这个例子当用户选择了以后,按"Jump"按钮提交表单,服务器接到申请后调用formjump.asp判断后定位到相应的URL。不过这里有一点要注意,HTTP标题已经写入到客户浏览器,任何HTTP标题的修改必须在写入页内容之前,遇到这种问题时,可以如下做:
在文件的开始<@ Language=..>后写:    
 

 Response.Buffer=True


在结尾定:

  Response.Flush


  这里Flush是Response的一个方法,它必须是Buffer属性设置为True时才能使用,否则会产生一个运行模式错误。另外一个Clear方法也是用于清除被缓存的页面,同样要Buffer属性设置为True时才能使用。


5、End方法

  该方法用于告知Active Server当遇到该方法时停止处理ASP文件。如果Response对象的Buffer属性设置为True,这时End方法即把缓存中的内容发送到客户并清除冲区。所以要取消所有向客户的输出民,可以先清除缓冲区,然后利用End方法。如:


<%
Response.buffer=true
On error resume next
Err.clear
if Err.number<>0 then
  Response.Clear
  Response.End
end if
%> 


0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com