Let's remember the very first ASP script written, the one that looked like this:
Response.Write("Hello World!")
Now, try to guess what response and write() are. Of course, response is a built-in object of ASP, while write() is one of its methods. You can introduce HTML tags in the string, it will be interpreted correctly:
Response.Write("<b> Hello World! </b>")
The response object can do things far more powerful than write text and ad HTML code to your page. As the name implies, its function is to send a response to the user, an output from the server. Now, this brings us one huge step closer to the initial goal of learning ASP, that is, to allow the creation of dynamic, interactive web pages.
For instance, one property for the response object is called ContentType. By default this is set to text/html, but you can change it to anything else, such as image, or a specific type of image, like JPEG or GIF, or a certain application. Let's take a look at the following example:
<% Response.ContentType="application/vnd.ms-excel" %>
<html>
<title> Excel Table </title>
<body>
<table>
<tr>
<td> Washington
<td> Paris
<td> London
<td> Moscow
</tr>
</table>
</body> </html>
As you can see, this is a simple HTML table, but the user will see it as an Excel table, as long as this piece of software is installed on the respective computer. If it's not installed, then, well, it wasn't such a great idea. You can use this feature to constrain the user to viewer to use a certain program, or to constrain the content to accept only a certain type of input.
You've seen the message "404 Not Found" hundreds of times on the Internet. It is caused by a property of the response object, called Status. It is often found in a conditional statement, such as If the ip address is . then Response.Status="404 Not Found" or "401 Unauthorized".
Another property is Expires, which establishes a period of time (expressed in minutes) to keep a page cached on a browser before it expires. There is also a version of this property called ExpiresAbsolute, which does the same, but sets a specific date and time for the page to expire. If you don't want the page to be cached at all, you can set the Expires property to a negative value.
Response.Expires = -1
The Buffer property decides whether to buffer the content of the page - meaning that the server will not allow the user to load the content of the page until it processes all the server scripts, or until it runs the methods Flush or End. If you want to use this method, you need to place it before the actual HTML code, and set it to "true". For the earlier versions of IIS (before 5.0), this was set by default to "false", but in the 5.0 and later versions, the default is "true". This is useful if you want the browser to finish performing a loop before showing anything to the user.
We've already met two methods of the response object, End and Flush. The End method puts an end to the script, and returns the result processed until the respective moment. The Flush method sends the HMTL content that has already been buffered without any delay (without waiting for the rest of the content to be buffered as well).
One method that is quite common is the Redirect, looking like this:
Response.Redirect("http://www.softwareprojects.org")
Now let's take a look at the request object, used to obtain information from the user. It is really valuable in connection with forms, as shown in the following chapter. It has a property called TotalBytes, which returns the number of bytes sent by the client's request. This is read-only, as you cannot modify this value:
X = Request.TotalBytes
After this, you can use the method called BinaryRead(a), to retrieve the data the user sent to the server as part of a POST request. The data will be stored in safe array. You need to specify the parameter a, which is how many bites you want the method to read from the user (value usually equal to the X variable returned by the TotalBytes property above).
Besides all these, the Request object also has collections, including ServerVariables (containing all the server variables), QueryString (with all the variables in a HTTP query string), forms and cookies, which are the most important, and will be discussed in the following chapters.
If you like this post then please subscribe to my full feed RSS. You can also subscribe by Email. Not sure how this works?










Leave a Reply