Although most wireless internet phones in the US will accept both
HDML and WML, you have decided to use HDML and ASP, (Active Server
Pages), for your application. This is a wise choice for the present,
but you may have noticed that there just is not much information out
there about using ASP to output HDML. Since there seems to be much
more information available about using ASP with WML
(www.wapuseek.com) and little to none on ASP and HDML, this article
will focus on the latter. In this article I will discuss:
Setting the MIME content-type for HDML in ASP
How to pass data from HDML to ASP
How to pass data from ASP to HDML
When to use Method and Postdata
How to use Vars with ASP
How to output reserved characters to HDML
How to access environment variables from ASP
Prerequisites
This article assumes that you have a basic working knowledge of HDML
and a basic working knowledge of ASP. If you need assistance with
HDML, information can be found at phone.com's developer site. If
you need assistance with ASP, there are tons of websites with
information, (Asp-Help.com and 15seconds.com are both great starting
points).
Content Type
One of the most frequently occurring problems when trying to get
HDML and ASP to work together is related to the MIME type. Setting
the MIME content type must be the first line of your ASP file,
without exception. Any white spaces, carriage returns, comments,
etc. that are before the content type definition will be
acknowledged and the server may not recognize the file. Therefore,
just leave them out. The correct line of code to start your ASP
file follows:
<% Response.ContentType = "text/x-hdml" %>
Passing Data from HDML to ASP
One of the main differences between using ASP to output HDML versus
HTML is the way in which you pass data. In order to pass a variable
from HDML to ASP you need to specify a destination option on the
card that will contain the data. A successful destination option
has the following form:
Dest = "nextpage.asp?var1=$(value1:esc)"
The variable name is defined in the Key option of the card element.
In this case the variable name is "var1". The variable is
set at the same time the user hits the accept key, so you will have
access to the value when you send the request for the next deck.
The destination address must go to another deck and not just a card.
If you substitute the name of a card in place of the next deck's ASP
file and keep the rest of the destination address in the same form,
then the server will be looking for a card named
"nextcard?var1=whatever". This card, of course, does not
exist. In this case, it will return to the first card in the deck.
This is most likely not the intended functionality, and if it is,
there are better ways of doing it.
We use the form $(value1:esc) for the actual value passed through so
that if there are any spaces or special characters in the value,
they will be escaped using URL conventions. (This is the same as
using URLEncode with your ASP variables). If you want to send the
value without the escaping characters (perhaps it is already URL
escaped) then use the form $(value1:noesc).
If an ASP page already has one or more variables and you are setting
another, you can pass them all, (or as many as you want) through to
the destination in the following form:
Notice that you can hardcode a value into a variable here also.
Example 1 – Passing data to ASP
Here is some sample code for two decks used to get a user's
password. We already have the user's name in a variable called
uName. We are passing the name, password and page number to
nextpage.asp.
The scope of a variable is defined by the activity in which it is
defined. You can access the variable anywhere within the activity
but not in other activities.
Passing Data from ASP to HDML
Passing a variable from ASP code to an HDML variable is much easier
– just set them equal. Here is a short example to demonstrate.
So the question is, when do you need to use the Method and Postdata
options for passing variables? You only need to use Method and
Postdata when passing a variable between pages in HDML and when you
do not need the value in the ASP code of your destination page.
Method and Postdata can be used in the following elements: Anchor,
Action, Choice, and Choice Entry. It is worth noting that the Entry
element does not use the Method and Postdata options, and Method and
Postdata cannot be used to transfer data to ASP variables.
Example 3 – Method and Postdata usage
The following example demonstrates how to use the Method and
Postdata options in a choice card. We take the user's choice in the
first card and return the value to the screen in the second card.
The variable "animal" gets passed through using Method and
Postdata.
Vars allows you to set a list of HDML variables as you pass from one
card to another. If you use Vars to set the values and then pass
them to the next deck, you will not be able to access those values
with your ASP code. Even if you try passing the variable names
through the destination option, the variable values are evidently
set after the request for the next deck is sent. However, if you
use Vars to pass the variables to another card first, then you can
successfully use the destination option to pass them to the next
deck and use the values in your ASP code. This is just one of many
opportunities for the Nodisplay card to be helpful.
Example 4 – Using Vars
This is an example of using Vars to set two variables and pass them
to a card before passing them to the next deck. This enables them
to be requested by the ASP code.
Another thing to be aware of when using ASP with HDML is reserved
characters. Make sure that when outputting the reserved characters
(<, >, ", &, $) to your HDML text you use their
respective escape sequences. See Table 1 below.
Character
Escape Sequence
<
<
>
≶
"
"
&
&
$
&dol;
ASCII character
nn; (nn is ASCII code)
Table 1 – Reserved Characters
(*Note – Don't leave the semicolon off the end!)
Example 5 – Reserved Characters
Since you can't use the formatCurrency function in ASP because it
outputs a dollar sign, here is an example of how to output a number
in typical US currency format.
When the WAP server you are using makes HTTP requests to an HDML
service, it adds headers that provide information about the
subscriber, the device and the server. The headers are converted to
environment variables, which you can use in your ASP code. The
following table lists the environment variables set by the UP.Link
HTTP request headers.
Environment Variable
Description
HTTP_ACCEPT
List of HDML versions accepted by device
HTTP_ACCEPT_LANGUAGE
Language in use on device
HTTP_COOKIE
HTTP cookies in standard format
HTTP_REFERER
URL of the deck originating the request
HTTP_USER_AGENT
Browser/version & Server/version
HTTP_X_UP_DEVCAP_CHARSET
Character set used by the device
HTTP_X_UP_DEVCAP_IMMED_ALERT
Specifies if device supports immediate alerts
HTTP_X_UP_DEVCAP_MAX_PDU
Maximum packet size supported by device (normally 1492 bytes)
HTTP_X_UP_DEVCAP_NUMSOFTKEYS
Number of softkeys on the device
HTTP_X_UP_DEVCAP_SCREENPIXELS
Width, Height of display in pixels
HTTP_X_UP_DEVCAP_SMARTDIALING
Specifies if device supports smart dialing
HTTP_X_UP_FAX_ACCEPTS
Specifies acceptable fax types
HTTP_X_UP_FAX_ENCODING
List of fax encoding types that the server accepts
HTTP_X_UP_FAX_LIMIT
Maximum fax size in bytes that the server accepts
HTTP_X_UP_SUBNO
Subscriber ID, globally unique device ID
HTTP_X_UP_UPLINK
The host on which the server is installed
Table 2 – Environment Variables
More detailed information about the specific environment variables
can be found at Phone.com's developer site.
In order to get the value of the environment variable into an ASP
variable, use the request.ServerVariables command with the desired
environment variable as the argument.
Example 6 – Environment Variables
The following example shows how to use ASP and environment variables
to redirect the device to the pages that are formatted to the
device's capabilities. If the device accepts HDML, it will be
redirected to index.hdml, an HDML file. Alternatively, if the
device accepts WML, it will be redirected to index.wml, a WML file.
<%
acceptHeader = Request.ServerVariables("HTTP_ACCEPT")
If Instr(acceptHeader, "hdml") <> 0 Then
Response.Redirect "index.hdml"
Else
Response.Redirect "index.wml"
End If
%>