Advertisment

Advanced WAP Programming

author-image
PCQ Bureau
New Update

To do some serious work in WAP (Wireless Application Protocol), you’ll need

dynamically generated pages that can pull data from within databases. WML

(Wireless Markup Language), which is used to create static WAP pages, can’t be

used for database connectivity because it’s a static markup language like

HTML. You need to write server-side scripts for database connectivity, for which

you can use PHP, Perl, JSP or ASP. Here, we’ll show you how to use these.

Advertisment

Before you start scripting, you have to configure your Web server for serving

WAP pages. You also need a good toolkit, which will emulate a WAP phone, so that

you can see what will be seen on the cellphone screen.

WAP toolkits

Various toolkits are available in the market, the most widely used ones being

the Nokia Toolkit 2 available at www.forum.nokia.com

and the UP Phone Toolkit at www.developer.phone.com.

Advertisment

Web server configuration

When a Web browser receives a page, it has to distinguish between HTML,

image, audio, and video. To enable this, with every response from the Web

server, a piece of header information is sent to the browser. This is known as

MIME (Multipurpose Internet Mail Extension). Some of the common MIME types

include text/html for HTML files and image/gif for GIF files. To enable the Web

server to serve WAP documents, it needs some new MIME types. These include:

Extension MIME type

Advertisment

WML text/vnd.wap.wml

WMLC application/vnd.wap.wmlc

WMLSC application/vnd.wap.wmlscriptc

Advertisment

WMLSCRIPT text/vnd.wap.wmlscript

WS text/vnd.wap.wmlscript

WSC application/vnd.wap.wmlscriptc

Advertisment

WMLS text/vnd.wap.wmlscript

WBMP image/vnd.wap.wbmp

The procedure for adding these MIME types varies from server to server. We’ll

do this for some common Web servers here. When you do this for your server, it

would be a good idea to check the documentation for the Web server you’re

running.

Advertisment

Apache

Locate the httpd.conf file (in /etc/httpd/conf), file and add the following

lines:

# WAP MIME Types

Advertisment

AddType text/vnd.wap.wml .wml

AddType image/vnd.wap.wbmp .wbmp

AddType text/vnd.wap.wmlscript .wmls

AddType application/vnd.wap.wmlc .wmlc

AddType application/vnd.wap.wmlscriptc .wmlsc

Save the file and restart Apache.

IIS (Internet Information Server)

On the server console, open the management console. From here, you can define

whether the MIME types will be valid for the entire server or for separate

directories. To add a MIME type to a directory, all you need to do is right

click on the directory to which you want to add the MIME type, select the HTTP

headers tag and click the File Types button at the lower right. Click New type

and supply the extension and the content type as listed above.

To add a MIME type to an entire server, right click on the server, click the

File Types button, and follow the same procedure as for adding MIME types to a

directory.

We now proceed to actual server-side scripting to generate dynamic WAP pages.

Generating dynamic WAP content

The script for generating WAP content with ASP, PHP, Perl, and JSP is given

here. In all cases except with ASP, we’ve given that part of the code that

tells your browser that WAP content is being sent to it and specify the MIME

type of the content. You can put in your actual content after this.

WAP with ASP

<%

Response.ContentType = "text/vnd.wap.wml"

%>

"http://www.wapforum.org/DTD/wml_1.1.xml">

<%

Response.Write"Welcome Visitors"

Response.Write " WAP is good "

%>

WAP with PHP

PHP is so flexible that one HTML document containing a PHP script can be used

for both HTML and WML compatible browsers. The PHP source code is invisible to

the client, just like ASP, and it’s up to you to either output HTML code or

WML. However, be extra careful here, as some built-in features of PHP output

HTML by default, typically error messages, which your WML micro-browser won’t

understand.

For example,

header("Content-type: text/vnd.wap.wml");

echo("\n");

echo("

\"http://www.wapforum.org/DTD/wml_1.1.xml\">\n\n");

?>

… Put your content here…

Using Perl

As with PHP, in Perl too, you first need to send the correct MIME type to the

browser. Here’s how to do it.

print "Content-type: text/vnd.wap.wml\n\n";

print "\n";

print " 1.1//EN\"\"http://www.wapforum.org/DTD/wml_1.1.xml\">\n\n";

….. Put your content here…..

Using Java servlets

Dynamic WML documents can be easily developed using Java servlets. Once you

know the WML syntax, building WAP applications using Java servlets can be an

easy task. Just set content type in your class and you can then send WAP tags.

The line

Response.setContentType("text/vnd.wap.wml");

defines the WAP MIME type to the browser. This is followed by

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class MobileDate extends HttpServlet {

public void service (HttpServletRequest request, HttpServletResponse

response) throws ServletException, IOException {

To set the content type for your wireless data:

response.setContentType("text/vnd.wap.wml");

PrintWriter out = response.getWriter();

Now, you can write what you would like to display on the user’s screen:

out.println("");

out.println(" 1.1//EN\"");

out.println(" \"http://www.wapforum.org/DTD/wml_1.1.xml\">");

out.println("");

out.println("");

out.println("

");

out.println("java with wap

");

out.println("

");

out.println("");

out.println("");

}

}

WAP pages are organized as a deck of cards, each card being one display page.

There is a limit to the size of a deck of WAP cards (all that is between

and
). The size depends on the WAP browser, and should not exceed

the following limits.

Browser

Size

limit
UP.Browser 3.2  1,492 bytes
UP.Browser 4.x  2,048 bytes
Ericsson R320 3,000 bytes (approx)
Ericsson R380 3,500 bytes (approx)
Ericsson MC218 8,000 bytes
Nokia 7110 1,397 bytes

(To be continued next month)



Gaurav Bhatnagar is a WAP project leader at rkmdaes.com

Advertisment