During a session, the Web browser passes data to the Web server in the form setTimeout Sets the timeout value for the current session, in
seconds. See getTimeout, keepAlive. setUserName Associates a user name with a session.
startAuditing Starts session auditing, beginning with the current page.
unlock Disables a lock that has been preventing other client threads from modifying data stored in the Session object.
whoAmI Returns a string containing the name of the currently executing function.
whoCalledMe Returns a string containing the name of the calling function.
Topic Refer to
Getting the value of a field “Retrieving field values” on page 117 Getting the value of a cookie “Retrieving cookie values” on page 121 Getting information about the Web
server and the remote host making the request
“Retrieving environment variables” on page 122
• If the form’s method is GET, the data is sent as part of the URL string, which looks something like this:
Name=Scott&Location=SouthPole&Button1=Submit
• If the form’s method is POST, the data is sent to the Web server in a separate message packet.
Field variables can come from other sources besides a form. For example, you might design a Web page that passes parameters on a link (using the link’s Query field). Or you might place in-line code on a Web page that calculates a value and passes it to the destination page. Each variable is passed as a name/value pair on the URL.
The catalog_main.html page from Haht_Intro demonstrates two methods of passing fields to a destination page.
First of all, each category (OUTDOOR, HOUSEHOLD, and so on) is actually an image which functions as a link to the destination page. The query string for the link contains the category of item being searched for — for example, “CatGrp=4” for Outdoor items. In addition, you can enter a product name and click on SEARCH BY NAME, which adds the name/value pair
Retrieving field values
Whether the data comes from a form or by some other means, a request typically includes a number of field variables. The Request object’s getURLField method lets you access these values without the need to determine whether the data was sent using GET or POST. Given a field name, getURLField returns the field’s value.
Returning to the Haht_Intro example, the destination page,
CatalogDisp.html, first tests to see if the query string has a value for
“CatGrp”; if that value is missing, it tests for a value for “SearchName.” It uses one of those values to define a shared query over the database.
Testing for a field’s existence
The Haht_Intro example tests for an empty string, which can mean one of two things: either the field cannot be found, or the field actually contains an empty string (""). If you simply want to check whether a field exists, use the getURLFieldExists or getURLFieldCount method.
Retrieving a field’s value by its index
If you call getURLField with an index into the collection of field variables, it returns the name/value string corresponding to that index. To retrieve the values of all fields in a form, you could use code like this:
HAHTtalk Basic
If aRequest.getURLField("CatGrp") <> "" Then ...
ElseIf aRequest.getURLField("SearchName") <> "" Then ...
sParam = "'%" & aRequest.getURLField("SearchName") & "%'" ...
End If
Java
for (int fieldNum=1; fieldNum<=aRequest.getURLFieldCount(); fieldNum++)
(Note that indexing into the field array is one-based, not zero-based.) In this case, each field would be returned as a name/value string, like this:
txtLastName=Simpson txtFirstName=Bart txtCity=Springfield Button1=Submit
If you index past the number of available fields, the method returns an empty string.
Fields with multiple values
Sometimes a form will have more than one value for the same field. For example, a list box like the one shown below contains multiple values, and the user can select more than one item in the list:
In this case, the browser sends a name/value pair, using the same fieldname, for each item selected — for example, "txtCity=Berlin&txtCity=Amsterdam". To retrieve these values, you use the same methods as above, but with an additional argument:
• getURLField (fieldname, n) returns the value of the nth occurrence of
fieldname.
• getURLFieldCount (fieldname) returns the number of values the browser sent for a particular field. A count of zero means that the field isn’t present in the form data; perhaps the user made no selection. • getURLFieldExists (fieldname, n) returns true if occurrence n of field
fieldname exists, and false otherwise.
HAHTtalk Basic
Dim FieldNum As Integer
For FieldNum = 1 to aRequest.getURLFieldCount() Print aRequest.getURLField(FieldNum) & "<BR>" Next FieldNum
Adding fields and overriding field values
On the destination page, you can call setURLField to override the value of a field, and you can call addURLField to set the value of an additional field, which will then behave as if it had been passed from the calling page.
Retrieving cookie values
A cookie is a string passed in the HTTP headers between a Web server and a browser. If the browser is configured to accept cookies, it will store the cookies on the user’s system and later, on request, will make the cookie available to the Web server. Information stored in cookies can include items such as user names, user preferences, or pages last visited. In HAHTsite, if the site is configured to use cookies, the state ID is also passed in a cookie.
The Response object contains methods to set cookies; the Request object, methods to retrieve cookie values. You retrieve cookie values just as you retrieve field values.
• getCookieCount returns the number of cookies sent from the browser. • getCookie(cookie) returns the value of the named cookie.
• getCookie(index) treats the cookies like an array and returns the cookie corresponding to the index argument; the first cookie has an index of one.
Retrieving cookie collections
A single cookie may store several pieces of data — for example,
“dimensions=height=10&width=5”. These multiple-value cookies are also called cookie collections. To retrieve these values, you must use the getCookie method and then parse the results. For example,
Java
String myCookie = aRequest.getCookie("dimensions");
HAHTtalk Basic
Retrieving multiple cookies with the same name
A cookie collection (above) refers to a single cookie with multiple values. However, you can also have several cookies with the same name but different paths. In this case, they are all sent with the request string, beginning with the deepest path. For example, the cookie with a path of “www/home/products” would appear on the string before “www/home.” If you simply call
aRequest.getCookie(cookie), you will retrieve the first cookie value on the string. However, you can also index into the set of cookies:
• getCookieCount(cookie) returns the number of values returned for this cookie.
• getCookie(cookie, index) returns the cookie value corresponding to
index.
For more information on cookies, including the path field, see “Setting cookies” on page 127.