introduction to hdml and asp

Upload: josue-lopez-acosta

Post on 31-May-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 Introduction to HDML and ASP

    1/5

    Intr oduc tion to HD ML and ASPBy: Christina Biggs

    Dilemma

    Although most wireless internet phones in the US will accept both HDML and WML, you have decided to useHDML and ASP, (Active Server Pages), for your application. This is a wise choice for the present, but you mayhave noticed that there just is not much information out there about using ASP to output HDML. Since thereseems to be much more information available about using ASP with WML (www.wapuseek.com) and little tonone 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 ofASP. If you need assistance with HDML, information can be found at phone.com's developer site. If you needassistance with ASP, there are tons of websites with information, (Asp-Help.com and 15seconds.com are bothgreat starting points).

    Content Type

    One of the most frequently occurring problems when trying to get HDML and ASP to work together is relatedto the MIME type. Setting the MIME content type must be the first line of your ASP file, without exception. Anywhite spaces, carriage returns, comments, etc. that are before the content type definition will beacknowledged and the server may not recognize the file. Therefore, just leave them out. The correct line ofcode to start your ASP file follows:

    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 passdata. In order to pass a variable from HDML to ASP you need to specify a destination option on the card thatwill 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 whenyou 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 inplace of the next deck's ASP file and keep the rest of the destination address in the same form, then theserver 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.

  • 8/14/2019 Introduction to HDML and ASP

    2/5

  • 8/14/2019 Introduction to HDML and ASP

    3/5

    Enter password:

    Method and Postdata

    So the question is, when do you need to use the Method and Postdata options for passing variables? Youonly need to use Method and Postdata when passing a variable between pages in HDML and when you donot need the value in the ASP code of your destination page. Method and Postdata can be used in thefollowing elements: Anchor, Action, Choice, and Choice Entry. It is worth noting that the Entry element doesnot use the Method and Postdata options, and Method and Postdata cannot be used to transfer data to ASPvariables.

    Example 3 Method and Postdata usage

    The following example demonstrates how to use the Method and Postdata options in a choice card. We takethe 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:

    Corgi

    Tiger

    Potbelly

    Next.asp:

    animal = $(animal)

    Vars

    Vars allows you to set a list of HDML variables as you pass from one card to another. If you use Vars to setthe values and then pass them to the next deck, you will not be able to access those values with your ASPcode. Even if you try passing the variable names through the destination option, the variable values areevidently set after the request for the next deck is sent. However, if you use Vars to pass the variables toanother card first, then you can successfully use the destination option to pass them to the next deck and usethe 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 nextdeck. This enables them to be requested by the ASP code.First.asp:

  • 8/14/2019 Introduction to HDML and ASP

    4/5

    Click to set variables.

    Next.asp:

    dog =

    cat =

    Reserved Characters

    Another thing to be aware of when using ASP with HDML is reserved characters. Make sure that whenoutputting the reserved characters (, ", &, $) to your HDML text you use their respective escapesequences. See Table 1 below.

    Character Escape Sequence

    < &lg;

    " "

    & &

    $ &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 exampleof how to output a number in typical US currency format.

    price = &dol;

  • 8/14/2019 Introduction to HDML and ASP

    5/5

    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 provideinformation about the subscriber, the device and the server. The headers are converted to environmentvariables, which you can use in your ASP code. The following table lists the environment variables set by theUP.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 alertsHTTP_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 developersite.In order to get the value of the environment variable into an ASP variable, use the request.ServerVariablescommand 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 pagesthat 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.