How do you create a single index file that generates both WML and HTML?
Several readers wrote in with this interesting question. Well, what I normally do is to create a server-side script (for instance,
using ASP) and name it, say, index.asp. The content of my index.asp file would look like this:
if InStr(Request.ServerVariables("HTTP_ACCEPT"), "wml") then
The MIME types that are acceptable to the device are stored in the environment variable HTTP_ACCEPT.
Of course, I am making a simplification here. I am assuming that all WAP devices send the MIME type strings containing the keyword "wml".
Such strings are "text/vnd..wap.wml", "text/vnd.wap.wmlscript" and "text/vnd..wap.wmlc". However, do be aware that some devices, most notably,
the Microsoft Mobile Explorer (MME), accepts both WML and HTML documents and as such may send multiple MIME type strings indicating
the ability to accept both WML and HTML content.
How can you identify the user's browser?
As the answer to the previous question shows, you can detect the kind of browser your user is using by checking the environment variable
HTTP_ACCEPT. However, this is not sufficient as different devices may exhibit different behaviors. As such, to further customize your
application, you might want to probe the kind of microbrowser the device is using. Fortunately, every device will send a string
containing the user agent type to the web server. To retrieve this string, simply check the HTTP_USER_AGENT environment variable:
if InStr(Request.ServerVariables("HTTP_USER_AGENT"), "Ericsson")then
'--- Loads the Ericsson-specific WML deck ---
if InStr(Request.ServerVariables("HTTP_USER_AGENT"), "Nokia")then
'--- Loads the Nokia-specific WML deck ---
'--- Loads the default generic UP WML deck ---
To display the user agent string for the various devices, you can use the following WML deck:
<% Response.ContentType="text/vnd.wap.wml" %>
<% =Request.ServerVariables("HTTP_USER_AGENT") %>
Developing Dynamic WAP applications
It is quite unlikely that you will be displaying content that is static in nature on a WAP device. After all, users use their
WAP device to retrieve time-sensitive information like stock quotes and weather information. As such, using WML and WMLScript alone
is not sufficient to develop compelling application for the mobile markets. You should familiarize yourself with a server-side technology.
Some of the current server-side technologies are:
- Microsoft Active Server Pages (ASP)
- Java Server Pages (JSP)
- Java Servlets
- Common Gateway Interfaces (CGI) using Perl, etc.
It is important to know that developing a WAP application is somewhat similar to developing a Web application, except that you are
working within a much-constrained environment.
WAP-Enabling Your Site
While there are WAP gateways (for example, the Nokia WAP Server) that are capable of converting your HTML pages into WML decks,
this technology is still pretty much in its infancy stage. A direct HTML to WML conversion often results in a clumsy user interface
on the WAP device. In any case, usability issues on the Web and WAP environments are totally distinct. It is thus difficult to transform
an HTML page that is designed to be displayed on a web browser to be displayed on a WAP device without some loss of usability.
The best advice you could get when you are designing a new WAP site is to take into consideration the target browsers that you
are planning to support. A good choice to markup the content of your web site is to use XML. And then based on the target device,
use XSLT to transform the XML content into either HTML or WML. If you already have a web site coded in HTML, consider converting
them into XHTML. XHTML is a version of HTML that is XML-compliant. Once that is achieved, you can use XSLT to perform the required
transformation. Of course, it is always easier said than done. But I see XML as the future for coding your web site.
For more information on XSLT and XML, visit this article
that I wrote for WirelessDevNet.com.
About Our Expert: Wei Meng LEE is the co-author of the upcoming book Beginning WAP: WML and WMLScript (ISBN: 1-861004-58-3),
to be published by Wrox Press. This book will be available in December, 2000. He can be reached via email at firstname.lastname@example.org.