ASP Response Object
The ASP Response object is used to send output to the user from the server.
Response Object
The ASP Response object is used to send output to the user from the server. Its collections, properties, and methods are described below:
Collections
Collection | Description |
Sets a cookie value. If the cookie does not exist, it will be created, and take the value that is specified |
Properties
Property | Description |
Specifies whether to buffer the page output or not | |
Sets whether a proxy server can cache the output generated by ASP or not | |
Appends the name of a character-set to the content-type header in the Response object | |
Sets the HTTP content type for the Response object | |
Sets how long (in minutes) a page will be cached on a browser before it expires | |
Sets a date and time when a page cached on a browser will expire | |
Indicates if the client has disconnected from the server | |
Appends a value to the PICS label response header | |
Specifies the value of the status line returned by the server |
Methods
Method | Description |
Adds a new HTTP header and a value to the HTTP response | |
Adds a string to the end of the server log entry | |
Writes data directly to the output without any character conversion | |
Clears any buffered HTML output | |
Stops processing a script, and returns the current result | |
Sends buffered HTML output immediately | |
Redirects the user to a different URL | |
Writes a specified string to the output |
ASP Request Object
The ASP Request object is used to get information from the user.
QueryString Collection Examples
Send query information when a user clicks on a link
This example demonstrates how to send some extra query information to a page within a link, and retrieve that information on the destination page (which is, in this example, the same page).
A QueryString collection in its simplest use
This example demonstrates how the QueryString collection retrieves the values from a form. The form uses the GET method, which means that the information sent is visible to everybody (in the address field). The GET method also limits the amount of information that can be sent.
How to use information from forms
This example demonstrates how to use the values retrieved from a form. We use the QueryString collection. The form uses the get method.
More information from a form
This example demonstrates what the QueryString contains if several input fields have the same name. It shows how to separate input fields with equal names from each other. It also shows how to use the Count keyword to count the "name" property. The form uses the get method.
Form Collection Examples
A form collection in its simplest use
This example demonstrates how the Form collection retrieves the values from a form. The form uses the POST method, which means that the information sent is invisible to others, and it has no limits (you can send a large amount of information).
How to use information from forms
This example demonstrates how to use the values retrieved from a form. We use the Form collection. The form uses the post method.
More information from a form
This example demonstrates what the Form collection contains if several input fields have the same name. It shows how to separate input fields with equal names from each other. It also shows how to use the Count keyword to count the "name" property. The form uses the post method.
A form with radio buttons
This example demonstrates how to interact with the user through radio buttons, with the Form collection. The form uses the post method.
A form with checkboxes
This example demonstrates how to interact with the user through checkboxes, with the Form collection. The form uses the post method.
Other Examples
Get the server variables
This example demonstrates how to find out the visitors (yours) browser type, IP address, and more with the ServerVariables collection.
Create a welcome cookie
This example demonstrates how to create a Welcome Cookie with the Cookies Collection.
Find the total number of bytes the user sent
This example demonstrates how to use the TotalBytes property to find out the total number of bytes the user sent in the Request object.
Request Object
When a browser asks for a page from a server, it is called a request. The ASP Request object is used to get information from the user. Its collections, properties, and methods are described below:
Collections
Collection | Description |
ClientCertificate | Contains all the field values stored in the client certificate |
Contains all the cookie values sent in a HTTP request | |
Contains all the form (input) values from a form that uses the post method | |
Contains all the variable values in a HTTP query string | |
Contains all the server variable values |
Properties
Property | Description |
Returns the total number of bytes the client sent in the body of the request |
Methods
Method | Description |
Retrieves the data sent to the server from the client as part of a post request and stores it in a safe array |
<%
dim fname
fname=Request.QueryString("fname")
If fname<>"" Then
Response.Write("Hello " & fname & "!
")
Response.Write("How are you today?")
End If
%>
<%
If Response.IsClientConnected=true then
Response.Write("The user is still connected!")
else
Response.Write("The user is not connected!")
end if
%>
ASP Quick Reference
ASP Quick Reference from W3Schools. Print it, and fold it in your pocket.
Basic Syntax
ASP scripts are surrounded by <% and %>. To write some output to a browser:
<% response.write("Hello World!") %>
The default language in ASP is VBScript. To use another scripting language, insert a language specification at the top of the ASP page:
<%@ language="javascript" %>
<%
....
%>
Forms and User Input
Request.QueryString is used to collect values in a form with method="get". Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send.
Request.Form is used to collect values in a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.
ASP Cookies
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests for a page with a browser, it will send the cookie too.
The Response.Cookies command is used to create cookies:
<%
Response.Cookies("firstname")="Alex"
Response.Cookies("firstname").Expires="May 10,2002"
%>
Note: The Response.Cookies command must appear BEFORE the tag!
The "Request.Cookies" command is used to retrieve a cookie value:
<%
fname=Request.Cookies("firstname")
response.write("Firstname=" & fname)
%>
Including Files
You can insert the content of one ASP file into another ASP file before the server executes it, with the #include directive. The #include directive is used to create functions, headers, footers, or elements that will be reused on multiple pages
Syntax:
or
Use the virtual keyword to indicate a path beginning with a virtual directory. If a file named "header.inc" resides in a virtual directory named /html, the following line would insert the contents of "header.inc":
Use the file keyword to indicate a relative path. A relative path begins with the directory that contains the including file. If you have a file in the html directory, and the file "header.inc" resides in html\headers, the following line would insert "header.inc" in your file:
Use the file keyword with the syntax (..\) to include a file from a higher-level directory.
Global.asa
The Global.asa file is an optional file that can contain declarations of objects, variables, and methods that can be accessed by every page in an ASP application.
Note: The Global.asa file must be stored in the root directory of the ASP application, and each application can only have one Global.asa file.
The Global.asa file can contain only the following:
Application events
Session events
TypeLibrary declarations
the #include directive
Application and Session Events
In Global.asa you can tell the application and session objects what to do when the application/session starts and what to do when the application/session ends. The code for this is placed in event handlers. Note: We do not use <% and %>, to insert scripts in the Global.asa file, we have to put the subroutines inside the HTML
It is also possible to create objects with session or application scope in Global.asa by using the