This article mainly introduces WML knowledge and 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//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
We call it a preface. It is marked later, and all our data is nested in these two tags. 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 tag is called deck, and the content on each screen is defined as card. Because WML is defined for wireless network transmission, the bandwidth limit is fully taken into account, we can include multiple cards in a deck and download them to the user agent together. In this way, we can switch between different screens locally to avoid going online each 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 // EN"
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 = "PasswZ success? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> vcmQ6">
<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//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>
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.