A detailed analysis of Wml--xml markup Language development example

Source: Internet
Author: User
Tags define definition query reference version client
XML This article mainly introduces the relevant knowledge of WML, how to develop WAP application.

WML is an xml-based markup language, and her official descriptions and specifications are maintained by the WAP forum. The document type definition for WML is an XML file type, Http://www.wapforum.org/DTD/wml_1.1.xml.

Like the HTML language, WML is to display data, and the purpose of XML is to describe the data, we define a series of tags and organize it into a syntax specification called a DTD (Document Type Definition). WAP-enabled handsets are installed with WAP browsers he can parse these tags and display them correctly on the phone screen.

This is usually the beginning of the text in WML.

<xml version='1.0'>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">


We call it the preamble. At the back is the tag, and all of our data is nested within the two tags. The number of WML tokens is very small and can be divided into two types, called Deck/card, which are called event. Here is not a single story, as we develop WML applications, the reference manual is available, and I give you an online reference: on-line WML Tag Reference.

Inside the tag we call it deck, the content of each screen we define it as card, because WML is defined for wireless network transport, we allow multiple card in a deck and can be downloaded to the user agent together, This allows us to switch to different screens locally and avoid networking every time. This, of course, adds to the burden on the client, so we should avoid including too many card in the deck.

Here we write a WML example TEST.WML, which reads as follows:


DOCTYPE WML public "-//wapforum//dtd WML 1.1//en"
"Http://www.wapforum.org/DTD/wml_1.1.xml" >





UserName :
john Doe paul Smith joe Dean bill Todd







Password:





you entered:

Name: $ (Name)

Password: $ ( Password)




In this deck contains three card, can download to the client, through the key operation we can switch between the different card, you can in the mobile phone or Winwap simulator to see the effect of the operation. Below is a screenshot of the run under Winwap.



Although we can already develop WML applications, these are all static content. What if we want to develop the function of interacting with the server? The answer, of course, is that we can use servlet technology. Look at the following example: <?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="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>


The user can select item from the list, transmit to the server through the wireless network after the servlet through the Request.getparameter () method to get the user's choice and send 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 you deploy the servlet and WML files correctly, you can see the contents of your selected XXXX after entering HTTP://222.28.218.222:8088/TEST2.WML confirmation under Winwap.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.