The Session object provides several methods for building a URL that you can use to link from a dynamic page to another page, to an image, or to an image map. These methods require either a project ID or a string representing the page, image, or image map.
Building a URL from a project ID
The getURL method locates a project item — a page, an image, or an image map — by means of its project IDand returns a string containing a URL for that item.
The getURL method has a number of variations, with different parameters, including:
• project ID — a universally unique identifier that HAHTsite assigns to a project item. Within the IDE, you can view a project item’s ID by clicking on the item, choosing Edit > Properties and clicking the File tab.
• default string — a string that is to be returned if the method fails to locate the item. This can occur if a project item was deleted but is still referenced somewhere in the source code. If you don’t specify a default string and the method fails, it returns an empty string.
• append string — a bookmark or query string to be appended to the generated URL. A bookmark consists of the pound sign (#), followed by the string for a bookmark anchor. A query string should contain one or more name/value pairs, separated by ampersands — for example, “Name=Johnson&City=London”.
• method (Java only) — the method to be run on the destination page. The method defaults to run. This argument is disregarded in HAHTtalk Basic projects.
• wantFullURL — a boolean value; if true, the method returns a complete URL, rather than a relative URL. You might set this value to true to produce a string to redirect users to another dynamic page. Some browsers require full URLs in this case. A full URL would look something
while a relative URL might look like this for the first dynamic page: StateId/TbOMAYMPp5MpKLxZ0G3xK_WCL1/HAHTpage/PJ2.HsPageTwo.run and like this for subsequent dynamic pages:
../HAHTpage/PJ2.HsPageTwo.run
Note that if state IDs are being passed in cookies, rather than on the URL, you will not see a state ID in the URL string returned.
The default for this argument is false — that is, relative URLs.
• wantStartURL — a boolean value; if true, the method returns a URL for calling the page from a static page, including the .htx or .hjx file and the “start=” string. It does not include a state ID, and it does start another session instance. If you set wantStartURL to true, you will always get a full URL, regardless of the setting for wantFullURL. Here’s an example of the string returned:
http://www.haht.com/cgi-bin/hsrun/webapps40/PJ2/ PJ2.hjx;start=PJ2.HsPageTwo.run
The default for this argument is false. Example: Building a URL
This example programmatically builds an anchor tag and target URL for a dynamic page, using relative URLs (the default). The example calls getURL, passing it the project ID for the destination page. Then it inserts the return value in an anchor tag.
At runtime, getURL adds the correct CGI delimiter (such as “?”), depending on the target Web server. If the call is being made from the first dynamic page of the application, then getURL returns a URL containing the state ID (if state IDs are being passed in URLs rather than cookies); the HTML for the anchor tag looks similar to this:
Java
String myURL = hahtSession.getURL
("74FC8E62E969D2119141748209C10000");
out.print("<A HREF=\"" + myURL + "\"> Page2 </A>");
HAHTtalk Basic
Dim MyURL As String
MyURL = hahtSession.getURL("74FC8E62E969D2119141748209C10000") Print "<A HREF=" & HSQUOT & myURL & HSQUOT & "> Page2 </A>"
<A HREF="StateId/T6SYOI8X3hdVAmTIbusmwsZ-
NK/HAHTpage/MyProject.HsPageTwo.run?"> PageTwo </A>
If this isn’t the first dynamic page in the sequence, then getURL returns a relative URL, and the HTML looks like this.
<A HREF="../HAHTpage/MyProject.HsPageTwo.run?"> PageTwo </A> (This is the output from a Java project; in a HAHTtalk Basic project, it would look the same, except that “HsPageTwo.run” would be replaced by
“HS_PageTwo.”)
If the Web server has been defined as storing state information in cookies, then the state ID is passed in a cookie instead of on the URL. For more information about cookies and Web browsers, see the HAHTsite IDE and IP User’s Guide, Chapter 4, “Working with Sites.”
Creating a dynamic URL for an image map, page, or file
In addition to the getURL method, there are three methods that return a dynamic URL for an image map, a dynamic page, or a file (for example, a secure static page), without requiring the project ID as an argument. Instead, you supply a string containing the name of the page, image map, or file. (There is a second, optional argument: the name of a subsite.)
These URLs can refer to elements outside the project, or even to elements that don’t yet exist (for example, files you will later copy to the approot directory). HAHTsite doesn’t check on the validity of the URL it creates; it simply accepts the input you supply and creates a URL by adding the state ID and the CGI delimiter for the Web server you’re publishing to.
• createPageURL creates a URL for a dynamic page. In a Java project, its argument is the page’s fully-qualified run method — that is,
packagename.classname.run. In a HAHTtalk Basic project, its argument is the name of the page subroutine (HS_pagename).
This code returns a dynamic page URL.
Java
String myPageURL =
• createMapURL creates a URL for an image map. Its argument is the filename for a dynamic server-side image map (.hmp).
This example displays a dynamic image map (“MyMap.hmp,” based on an image “Globe.gif”). It calls two Session methods: one to create a dynamic map URL, and one to create a static URL (for more information on that method, see “Creating a static URL” on page 113).
• createFileURL creates a URL for a file stored in the approot directory, such as a secure static page.
This code returns a URL for a secure static page.
Java
out.print("<P><A href=\"" +
hahtSession.createMapURL("MyImageMap.hmp", "default") + "\"><img src=\"" + hahtSession.createStaticURL("Globe.gif", "default") + "\" border=\"0\" height=\"128\" width=\"144\" ismap></A></P>");
HAHTtalk Basic
Print "<P><A href=" & HSQUOT & _
hahtSession.createMapURL("MyMap.hmp", "default") _ & HSQUOT & "><IMG src=" & HSQUOT & _
hahtSession.createStaticURL("Globe.gif", "default") & _ HSQUOT & " border=" & HSQUOT & "0" & HSQUOT & " height=" _ & HSQUOT & "128" & " width=" & HSQUOT & "144" & HSQUOT & _ " ismap></A></P>" & HSCRLF
Java
String myFileURL =
hahtSession.createFileURL("MySecurePage.html");
HAHTtalk Basic
Dim MyFileURL As String