Proceed to WirelessDevNet Home Page
Publications, e-books, and more! Community Tutorials Store Downloads, tools, & Freebies! IT Career Center News Home
newnav.gif

Newsletters
EMail Address:



   Content
  - Articles
  - Columns
  - Training
  - Library
  - Glossary
 
   Career Center
  - Career Center Home
  - View Jobs
  - Post A Job
  - Resumes/CVs
  - Resource Center
 
   Marketplace
  - Marketplace Home
  - Software Products
  - Wireless Market Data
  - Technical Books
 
   News
  - Daily News
  - Submit News
  - Events Calendar
  - Unsubscribe
  - Delivery Options
 
   Community
  - Discussion Boards
  - Mailing List
  - Mailing List Archives
 
   About Us
  - About WirelessDevNet
  - Wireless Source Disks
  - Partners
  - About MindSites Group
  - Advertising Information
 
INDEX
>Introduction
>Enhdyra Mini-HOWTO
>
Configuring Enhydra for WAP
>The HelloWAP Application
>Screenshots
 

Serving Up WAP with Enhydra

The HelloWAP Application

Striving for simplicity here, I built a basic multi-card WML document that simply takes data from an input field in one card, passes it to another card, and prints it out. Pretty simple, I know, but if you want more WML info, check out our WML Tutorial. Ok, here's the code:

Welcome.wml

<?xml version='1.0'?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card id="card1" title="HelloWAP"> <p> <em>Welcome to HelloWAP</em> <br/> Enter your name: <input type="text" name="uname"/> <do type="accept" label="Login"> <go href="#card2"/> </do> </p> </card> <card id="card2" title="Results"> <p> <em>Hello, $(uname)!</em> <br/> Pretty cool, huh? <do type="accept" label="Back"> <go href="#card1"/> </do> </p> </card> </wml> Copy this or type it and save it as Welcome.wml in the HelloWAP/helloWAP/presentation directory. You don't have to delete the Welcome.html file, Enhydra will just overlook it because of the changes we made to the Makefile in this directory.

Now, all that's left is to write the Welcome.java code so that Enhydra will serve up the WML. There already exists a Welcome.java file in the presentation directory, but that code is for serving up HTML pages, not WML. Rename the existing Welcome.java file and create a new one so you can compare the changes. Here is the new code:

Welcome.java

package helloWAP.presentation; import com.lutris.appserver.server.httpPresentation.HttpPresentation; import com.lutris.appserver.server.httpPresentation.HttpPresentationComms; import com.lutris.appserver.server.httpPresentation.HttpPresentationException; import com.lutris.appserver.server.httpPresentation.HttpPresentationOutputStream; import com.lutris.appserver.server.httpPresentation.HttpPresentationRequest; import com.lutris.appserver.server.httpPresentation.HttpPresentationResponse; import org.enhydra.xml.xmlc.XMLObject; import java.io.IOException; public class Welcome implements HttpPresentation { public void run(HttpPresentationComms comms) throws HttpPresentationException, IOException { WelcomeWML welcome = (WelcomeWML)comms.xmlcFactory.create(WelcomeWML.class); present(welcome,comms); } public void present(XMLObject doc, HttpPresentationComms comms) throws HttpPresentationException, IOException { HttpPresentationResponse response = comms.response; response.setContentType("text/vnd.wap.wml"); HttpPresentationOutputStream out = response.getOutputStream(); String buffer = doc.toDocument(); out.println(buffer); response.flush(); } } There are a few interesting things to note here. First off, I explicitly imported the classes needed to present WML instead of just importing *, but it gives you a better idea what classes are needed for WML to work. Now, let's analyze the code. The line:

WelcomeWML welcome = (WelcomeWML)comms.xmlcFactory.create(WelcomeWML.class);

creates a WelcomeWML (created from compiling the Welcome.wml file) object called 'welcome'. The somewhat complicated looking assignment is for automatic recompilation of HTML (WML in our case) so that you could change the WML file and the presentation object would change accordingly without having to recompile the whole project. The 'present' function creates a typical servlet response object, sets the content type for WAP, and does an out.println to send the WML to the browser. Pretty straight forward servlet stuff, with a little Enhydra seasoning thrown in. Now, the java code doesn't do much of anything dynamic, it just sends the WML code straight to the browser, but this would be where you would change a tag or add additional text or whatever.

Once you have all the code written, simply go back to the top-level HelloWAP directory, do a

make and you're golden. CD into HelloWAP/output, type: ./start browse to http://localhost:9000/ (you may want to add the ending '/', some browsers are finiky about this) with your favorite WAP-enabled browser (phone.com's UP.SDK 4.0 works well) and watch your brand-new Enhydra-powered WAP application go. Pretty cool, huh? Well, that should get your feet wet with Enhydra and WAP. If you want to delve deeper, check out the Enhydra documentation or enhydra.org.

Next: Screenshots
Sponsors

Search

Eliminate irrelevant hits with our industry-specific search engine!









Wireless Developer Network - A MindSites Group Trade Community
Copyright© 2000-2010 MindSites Group / Privacy Policy
Send Comments to:
feedback@wirelessdevnet.com