Java Reference
In-Depth Information
Using this basic functionality, it is possible to construct dynamic Java servlets that generate
WML content based on JDBC database queries or other typical programming tasks. What hap-
pens, though, when your boss asks you to develop one common set of code that supports both
desktop (for example, HTML) users and mobile (for example, WAP) users? This will be the
topic of the following two sections.
Multiple Device Support
As you might imagine, supporting a completely different code base for HTML and WML con-
tent would become unmanageable quickly on any moderate-to-large-sized project. In order to
“force” all users to enter through a central servlet, it is useful to first detect the browser type
and then redirect the user to the appropriate content. This way, all users enter your server appli-
cation through one servlet and WML/HTML output code within that servlet can access the
same core set of helper methods and classes. (In fact, only the text output methods will differ!)
User agents can be detected using the
javax.servlet.http.HttpServletRequest.getHeader() method to retrieve the
HTTP_USER_AGENT CGI Environment Variable. The following line of code does just that:
String userAgent = request.getHeader(“User-Agent”);
This is a rather tedious approach but enterprise developers should be able to narrow down the
list of potential accessors somewhat. For an up-to-date list of WAP user agent values, visit
http://allnetdevices.com/faq/useragents.php3 .
Maintaining a Site in XML
A common approach in use today by wireless application developers is to store the site content
and data in XML format. XML documents can be transformed into any number of formats
using an XML technology known as eXtensible Stylesheet Language Transformation ,or XSLT .
WML is particularly suited to this sort of transformation because it is itself based on XML,
making the transformation very clean and straightforward. If you are familiar with object-
oriented programming concepts, you will recognize the concepts of data hiding and
encapsulation—two concepts enthusiastically supported by XML and XSLT.
The actual formatting of the body to be displayed to the user (for example, WML or HTML) is
stored in an XML file. The data stored within that formatted body is stored within a separate
XML file and united with the formatting XML using an XML parser. Some HTML clients
(such as Microsoft Internet Explorer 5.0 and later releases) support XML/XSLT in the client;
therefore no further work will be required. At the current time, WAP browsers do not embed
XML parsers, so processing will need to be completed on the server by a Java servlet and a
Java XML parser framework such as that provided by the Apache Cocoon project
( http://xml.apache.org/cocoon/ ).
Search WWH ::




Custom Search