the complete webmaster
tutorials reviews reference
ASP
CGI
FrontPage
HTML
Java
JavaScript

home / articles / asp

A Change of Method

Based on what we've learned so far, what happens when we change the METHOD attribute of the HTML form from POST to GET? or vice-versa?  Its certainly not unheard of to do so.

Based on the amount of data you're attempting to send to the host and based on just how much information you want to display in the address line of your browser you may choose to submit data to the server using GET rather than POST.

We learned that when using the GET method, values from the form are populated in the QueryString collection instead.

Let's take the same form with some minor changes:

<FORM METHOD="GET" ACTION="MYREQUEST.ASP">

This change instructs the browser to submit the data contained on the form by appending all name/value pairs to the end of the URL.  For example, if the values for Field1 and Field2 are the values 'First' and 'Second' respectively, the resulting URL for this request would end up looking something like this:

http://www.myserver.com/MYREQUEST.ASP?Field1=First&Field2=Second

Given that request, in our ASP script, could do something like this:

<%
For Each Item in Request.QueryString
Response.Write Request.QueryString( Item ) & "<BR>"
Next
%>

This script would execute and produce a list, separated by an HTML Break tag, of values contained in the collection.

Notice the introduction of some new syntax.  I'll take a moment to explain because this code will be reusable in one fashion or another throughout the remainder of this article.

First, the focus of this code  is the QueryString collection and our desire to iterate over every item contained therein.  We do that with a FOR/EACH/NEXT statement.  FOR/EACH is similar to FOR/NEXT except it has intimate knowledge of collections and understands when you've reached the end of one, as in the example above.

We also introduce yet another built-in object, the Response Object.  We'll talk more about this object in the future, however, for now the code above simply 'Writes' the values contained in the QueryString collection to the HTTP response stream, in effect, sending it back to the requesting browser.

Other Request Trivia

You can also access a member of either collection in the Request Object directly without explicitly specifying the name of the collection.  For example:

Request("Field1")

If you do so, remember that the server will search the Request object collections for the variable in the following order:

1. QueryString
2. Form
3. Cookies
4. ClientCertificate
5. ServerVariables

Page 1: A Brief History of Objects
Page 2: COM is the Basis for Microsoft's Object Strategy
Page 3: Using Objects and Object Models
Page 4: Active Server Pages Objects
Page 5: Requests and Responses: An HTTP Perspective
Page 6: Using the Request Object
Page 7: A Change of Method
Page 8: Using Other Collections
Page 9: Tip of the Week and Summary

Author: Keith Cox
Date: 12/29/97

More articles about Active Server Pages
More articles by Keith Cox
Author Biography

write for us about us advertise

Copyright 1997, 1998 A Big Lime. All rights reserved.

body>