欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

javascript asp教程第七课--response属性

程序员文章站 2023-12-04 18:05:04
below is a table of response properties along with examples and explanations. re...

below is a table of response properties along with examples and explanations.

response properties
buffer response.buffer = true
allows for the buffering of output
cachecontrol response.cachecontrol="public"
sets cache to "public" or "private"
charset response.charset="windows-1252"
sets the iso character set
contenttype response.contenttype="text/html"
specifies the output mime type (text/html, text/plain, gif, jpg)
expires response.expires=60
sets page expiration in minutes
expiresabsolute response.expiresabsolute=#january 31, 2003 13:00:00#
sets time certain for page to expire
isclientconnected if (response.isclientconnected==true) { }
determines if client is still connected
pics ((see explanation))
platform for internet content selection
status response.status="401 unauthorized"
sets page status

you are not required to set, alter, or utilize a single response property if you don't want to. having said that, they can be handy once in while. i've demonstrated all but two properties in the script below.

by the way, set your properties before you begin output to the client.

get started:

below is the asp script for lesson 07.

<%@language="javascript"%>
<%
response.buffer=true
response.cachecontrol="private" 
response.charset="windows-1252"
response.contenttype="text/html"
response.expires=-1
response.status="200 ok"
%>
<html>
<body>
<%
if (response.isclientconnected==true)
	{
	response.write("the client is connected.<br>")
	}
else
	{
	response.end()
	}
%>
<table border="2">
<tr>
<%
for (x=1;x<=200;x++)
	{
	response.write("<td>" + x + " </td>\r")
	if (x%10==0)
		{
		response.clear()
		}
	if (x%4==0)
		{
		response.write("</tr></table>\r")
		response.write("<table border=\"2\">")
		response.write("\r<tr>")
		response.flush()
		}
	}
%>
</tr></table>
</body>
</html>

click here to run the script in a new window. after you click onto the link, really study the numbers. see if you notice anything weird about the page, like missing numbers.

response.buffer:

let's take the properties in order of appearance in our script. response.buffer allows us to control the output via response.flush() and response.clear(). if you haven't already, click onto the link to run the script. you'll get a strange output with some of the numbers missing. the missing numbers are thanks to response.clear(). you might notice that response.flush() slows down the server tremendously. don't use this method without a reason.

response.cachecontrol:

cachecontrol gives you the power to authorize proxy servers to keep your page in cache. (that would be the "public" setting.) likewise, it allows you to disallow proxy servers from caching your page. (that would be the "private" setting). the default is "private."

response.charset:

charset allows you to specify the character set, for example: "iso 8859-1".

response.contenttype:

contenttype allows you to indicate the mime type of the output. for example there is text/plain and text/html. there is also gif and jpeg.

response.expires:

expires allows you set an expiration time for the page. by setting the expires property to -1, you are saying the page expired one minute before it was delivered. the browser will (hopefully) not store it in cache, but rather make a separate request to the server before re-displaying the page.

response.status:

if tomorrow congress were to pass a law forbidding the use of response.status, i think life would go on. if it makes you happy, use it.

response.isclientconnected:

isclientconnected does exactly what it says. it returns a boolean value that you can use in an "if" statement.

response.pics:

pics stands for platform for internet content selection. it allows pages to be rated for the presence of violence, sexuality, language and nudity. there are services on the internet to rate your site. i've never used one. i found a sample pics string on the internet and i converted to javascript.

response.pics("(pics-1.1 <http://www.rsac.org/ratingv01.html> labels on \"1997.01.05t08:15-0500\" until \"1999.12.31t23:59-0000\" ratings (v 0 s 0 l 0 n 0))")

it's a long string and your browser may have wrapped the text down to a second line. if that's the case, then you have to pretend that the entire pics string is on one line.

response.expiresabsolute:

i did not demonstrate expiresabsolute in the script because i already used response.expires. expiresabsolute does exactly the same thing as expires, except it uses a date and time certain. (i couldn't see using both in the same script.) the only thing i would point out is the pound signs (#) at the beginning and and of the date.