Professional Documents
Culture Documents
Introduction To HDML and ASP
Introduction To HDML and ASP
Dilemma
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:
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:
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:
Dest="nextpage.asp?var1=$(value1:esc)&var2=<%=value2%>&var3=hardcodedValue"
Notice that you can hardcode a value into a variable here also.
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.
First.asp:
<%response.ContentType = "text/x-hdml"%>
<hdml version=3.0>
<%uName = request.queryString("uName")%>
Next.asp:
<%response.ContentType = "text/x-hdml"%>
<hdml version=3.0>
<%
uName = request.queryString("uName")
pass = request.queryString("pass")
page = request.queryString("page")
%>
<display>
Password:<br>
<wrap><%=uName%>
<wrap><%=pass%>
<wrap><%=page%>
</display>
</hdml>
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 a variable from ASP code to an HDML variable is much easier – just set them equal. Here is a short
example to demonstrate.
<%response.ContentType = "text/x-hdml"%>
<hdml version=3.0>
<%uName = request.queryString("uName")%>
</hdml>
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.
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.
First.asp:
<%response.ContentType = "text/x-hdml"%>
<hdml version=3.0>
<choice key=animal>
<action type=accept task=go dest="next.asp" method=post postdata="animal">
<ce value="Corgi">Corgi
<ce value="Tiger">Tiger
<ce value="Potbelly">Potbelly
</choice>
</hdml>
Next.asp:
<%response.ContentType = "text/x-hdml"%>
<hdml version=3.0>
<display>
animal = $(animal)
</display>
</hdml>
Vars
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.
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.
First.asp:
<%response.ContentType = "text/x-hdml"%>
<hdml version=3.0>
<display>
<action label="Select" type=accept task=go dest="#next" vars="dog=Corgi&cat=Tiger">
Click to set variables.
</display>
<nodisplay name=next>
<action label="Select" type=accept task=go
dest="temp2.asp?dog=$(dog:esc)&cat=$(cat:esc)">
</nodisplay>
</hdml>
Next.asp:
<%response.ContentType = "text/x-hdml"%>
<hdml version=3.0>
<%
dog = request.queryString("dog")
cat = request.queryString("cat")
%>
<display>
<action label="Back" type=accept task=prev>
<wrap>dog = <%=dog%>
<wrap>cat = <%=cat%>
</display>
</hdml>
Reserved Characters
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.
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.
<%response.ContentType = "text/x-hdml"%>
<hdml version=3.0>
<%price = 12%>
<display>
<wrap>price = &dol;<%=formatNumber(price, 2, -1)%><br>
</display>
</hdml>
This is what the output will look like:
$12.00
Environment Variables
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.
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.
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
%>