网络编程
位置:首页>> 网络编程>> Asp编程>> 详细介绍ASP内置对象Response(2)

详细介绍ASP内置对象Response(2)

  发布时间:2008-06-23 12:42:00 

标签:Response,对象,函数,字符串,asp


    四,Response.redirect

Redirect 方法是让浏览器立即重定向到程序指定的URL地址。这在根据客户的不同响应,为不同的客户指定不同的页面,或根据不同的情况指定不同的页面时,显得非常重要。

    该方法是立即生效的,在其后的脚本都不执行。

    5,redirect.asp

<%response.redirect("https://www.aspxhome.com/")%>

以上四则运用属于Response对象的几个比较重要的方法:write、end、clear、redirect等当然方法还有:AddHeader、AppendToLog、BinaryWrite、Flush……

    早说过,一个ASP对象除了对象方法外,还有对象属性

    那response对象的属性有哪些呢?

    五,Response.ContentType

ContentType 属性指定服务器响应的 HTTP 内容类型。如果未指定 ContentType,默认为 text/html。

6,contenttype.asp(非text/html的)

<% Response.ContentType = "text/HTML" %>
<% Response.ContentType = "image/GIF" %>
<% Response.ContentType = "image/JPEG" %>
<% Response.ContentType = "text/plain" %>
<% Response.ContentType = "image/JPEG" %>

六,Response.charset

Charset 属性将字符集名称附加到 Response 对象中 content-type 标题的后面,用来设置服务器响应给客户端的文件字符编码。

7,charset.asp


<% Response.charset = "big5" %>

中文显示,但采用的big5繁体的编码,所以看到的是乱码。

当然Response.ContentType和Response.charset应用得比较少了。直接在head头部属性里面添加就OK了。

七,Response.expires

该属性指定了在浏览器上缓冲存储的页,距过期还有多少时间。

    如果用户在某个页过期之前又回到此页,就会显示缓冲区中的页面。

    但若设置 response.expires=0,则可使缓存的页面立即过期。

这是一个较实用的属性,当客户通过 ASP 的登陆页面进入 WEB 站点后,应该利用该属性使登陆页面立即过期,以确保安全。

8,expires.asp

<%
Response.Expires = 0 
Response.Expiresabsolute = Now() - 1 
Response.AddHeader "pragma","no-cache" 
Response.AddHeader "cache-control","private" 
Response.CacheControl = "no-cache" 
%> 

八,Response.status

设置服务器要响应的状态行的值。Response.status="状态描述字符串",字符串可以为一个三位整数或一串说明文字组成,但必须防在<html>之前。

9,status.asp

<% Response.Status = "401 Unauthorized" %>

九,Response.buffer

比较重要的一个,值为true or false。该属性指示是否缓冲页输出。

引用:当缓冲页输出时,只有当前页的所有服务器脚本处理完毕或者调用了 Flush 或 End 方法后,服务器才将响应发送给客户端浏览器,服务器将输出发送给客户端浏览器后就不能再设置 Buffer 属性。因此应该在 .asp 文件的第一行调用 Response.Buffer。

Response.buffer=true

对于Response对象的属性和方法先到这里,剩下一个数据集合,即cookie。继续看cookies讲座吧。

应用举例题

表单发OutLook邮件

<style>
input{ border:1px solid navy; width:150}
</style>
<script>
function test(){
var NewTitle=title.value;
var NewContent=content.value;
document.location.href="mailto:"+aaa.value+"?cc="+bbb.value+"&bcc="+ccc.value+"&subject="+NewTitle+"&body="+NewContent;
}
</script>
<pre>
<font color=red>收件人:  </font><input name=aaa><br>
<font color=red>操送:   </font><input name=bbb><br>
<font color=red>密件操送: </font><input name=ccc><br>
<font color=red>主题:   </font><input name=title><br>
<font color=red>内容:   </font></pre><p>
<textarea cols=30 rows=10 name=content></textarea><br>
<input type=button value="send" onClick="test()"> 

ASP:

<%
submitname=request.form("submit")
if submitname="submit" then
email=request.form("email")
cc=request.form("cc")
subject=request.form("subject")
body=request.form("body")
response.redirect("mailto:"&email&"?cc="&cc&"&subject="&subject&"&body="&body)
else
%>
<form name="form1" method="post" action="email.asp">
email:<input name="email"><br>
cc:<input name="cc"><br>
subject:<input name="subject"><br>
body:<input name="body"><br>
<input type="submit" name="submit" value="submit">
</form>
<%end if%> 
0
投稿

猜你喜欢

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