Can I use WML (wireless markup language) from a Java Server Page?

Shaun Childers

Follow these steps for using WML instead of HTML from within JSP.

1) Make sure that the following is added to your MIME types file of your web server and restart it: File Extension = .wml MIME Type = text/vnd.wap.wml

2) (From this point forward, you would do the following inside your servlets just as you would inside your JSP files.) In your JSP file set your response type to text/wml (normally it's text/html or text/plain for HTML).

3) Instead of outputting HTML code inside your JSP file, you just output WML code. You can do this different ways: you can just use the

or you could create WML classes in Java and just have a class for each WML tag (WML is a small set of HTML, so you will have around 30 classes). Each WML class would appropriately handle the syntax specific to itself and handle you placing data into this syntax. Each class would also have a toString() method. From here, in your JSP file, wherever you want your WML code, just write Java (you have the WML classes), then to output the WML code, you would write out.println(wml.toString()); The wml.toString() method would call all of the other classes' (Card, Select, etc.) toString() method to output all of the WML syntax. This design works well because if the WML syntax changes and you have 100 JSP files with WML syntax inside, you would have to change every one on them; using the WML classes, if the WML syntax changes, you just have to change that particular class associated to whatever tag changed, and then recompile your class.

Now, keep in mind that there is one problem with outputting WML through JSP - if your web phone is trying to call a JSP file (not through a servlet), and there is a problem in which the JSP file outputs an error, whatever is handling your JSP files will probably output an error in HTML format, not WML, and therefore your phone browser will not be able to interpret this and will give you an error page built into the phone browser. For example, if you are using JRun to run your JSP files and it is not up and running, you will receive an error in HTML. You could develop an error handling system for capturing JSP errors and if you are expecting WML, you could return an error page in WML.