Article Title: WAP development entry-Build a Development Environment
Author: mingjava
Last Updated: 15:34:35
Clicks: 82 "href =" http://www.j2medev.com/Article_Show.asp? ArticleID = 76 "target =" _ blank "> getting started with WAP Development -- Building a development environment describes how to build a development environment for WAP applications. This chapter describes the knowledge of WML, how to Develop WAP applications.
WML is an XML-based markup language. Its official instructions and specifications are maintained by the WAP Forum. WML document types are defined as XML file types, http://www.wapforum.org/dtd/wml_1.1.xml. Like HTML, WML is used to display data, while XML is used to describe data, we define a series of tags and organize them into syntax specifications. We call them document type definition ). WAP browsers are installed on mobile phones that support WAP. They can parse these tags and display them correctly on the mobile phone screen.
This is usually found at the beginning of WML text.
<XML version = '1. 0'>
<! Doctype WML public "-// wapforum // dtd wml 1.1 //" http://www.wapforum.org/DTD/wml_1.1.xml ">
We call it a preface. The <WML> </WML> mark is followed, and all our data is nested in these two marks. There are very few WML tags, which can be divided into two types: deck/card and event. I cannot tell you one by one here. We can refer to the manual when developing WML applications. I will provide you with an online reference: Online WML tag reference. The content in the <WML> </WML> label is called deck. The content of each screen is defined as card. Because WML is defined for wireless network transmission, fully considering the bandwidth restrictions, we allow multiple cards in a deck to be downloaded to the user agent together, so that we can switch between different screens locally, avoid connecting to the Internet every time. Of course, this also adds a burden on the client, so we should avoid adding too many cards to the deck.
The following is an example of WML test. WML. The content is as follows:
<? XML version = '1. 0'?>
<! Doctype WML public "-// wapforum // dtd wml 1.1 //" http://www.wapforum.org/DTD/wml_1.1.xml ">
<WML>
<Card id = "login" Title = "login">
<Do type = "accept" label = "password">
<Go href = "# password"/>
</DO>
<P>
Username:
<Select name = "name" Title = "name:">
<Option value = "John Doe"> John Doe </option>
<Option value = "Paul Smith"> Paul Smith </option>
<Option value = "Joe Dean"> Joe Dean </option>
<Option value = "Bill Todd"> Bill Todd </option>
</SELECT>
</P>
</Card>
<Card id = "password" Title = "Password:">
<Do type = "accept" label = "Results">
<Go href = "# results"/>
</DO>
<P>
Password: <input type = "text" name = "password"/>
</P>
</Card>
<Card id = "Results" Title = "results:">
<P>
You entered: <br/>
Name: $ (name) <br/>
Password: $ (password) <br/>
</P>
</Card>
</WML>
The deck contains three cards, which can be downloaded to the client at the same time. by pressing the keys, we can switch between different cards, you can check the running effect on your mobile phone or winwap simulator. Below is the running of winwap.
Although we can already develop WML applications, these are static content after all. What if we want to develop a function that interacts with the server? The answer is, of course, Servlet technology. See the following example:
<? XML version = '1. 0'?>
<Doctype WML public "-// wapforum // dtd wml 1.1 //" http://www.wapforum.org/DTD/wml_1.1.xml ">
<WML>
<Card id = "order" Title = "query inventory">
<P>
<Select name = "items" Title = "items">
<Option value = "books"> books </option>
<Option value = "Music"> music </option>
<Option value = "video"> video </option>
<Option value = "software"> Software </option>
</SELECT>
</P>
<Do type = "accept" label = "query">
<Go href = "http: // 222.28.218.222: 8088/WAP/wapservlet" method = "get">
<Postfield name = "items" value = "$ (items)"/>
</Go>
</DO>
</Card>
</WML>
You can select an item from the list and transmit it to the server over a wireless network. Then, the servlet uses the request. getparameter () method to obtain the user's selection and send it to the user. The servlet code is as follows:
Package com. j2medev. mingjava;
Import java. Io. ioexception;
Import java. Io. printwriter;
Import javax. servlet. servletexception;
Import javax. servlet. http. httpservlet;
Import javax. servlet. http. httpservletrequest;
Import javax. servlet. http. httpservletresponse;
Public class wapservlet extends httpservlet
{
Protected void doget (httpservletrequest request,
Httpservletresponse response) throws servletexception, ioexception
{
String select = request. getparameter ("items ");
Response. setcontenttype ("text/vnd. WAP. WML ");
Printwriter out = response. getwriter ();
Out. println ("<? XML version =/"1.0/"?> ");
Out. println ("<! Doctype WML public/"-// wapforum // dtd wml 1.1 // en /"");
Out. println ("/" http://www.wapforum.org/DTD/wml_1.1.xml/ "> ");
Out. println ("<WML> ");
Out. println ("<Card Title =/" test/"> ");
Out. println ("<p align =/" center/"> ");
Out. println ("You selected" + select );
Out. println ("</P> ");
Out. println ("</card> ");
Out. println ("</WML> ");
}
Protected void dopost (httpservletrequest request,
Httpservletresponse response) throws servletexception, ioexception
{
Doget (request, response );
}
}
After correctly deploying the servlet and WML files, enter http: // 222.28.218.222: 8088/test2.wml under winwap to confirm that the content of your selected XXXX is displayed.