wml入门之与服务器端交互

首先我用的IDE环境是MyEclipse,构建的一个web项目前端用.wml,服务器端用servlet.

看我的前端代码。

<?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://192.168.1.5:8080/AjaxTrain/servlet/wapServlet" method="get">
<postfield name="Items" value="$(Items)"/>
</go> 
</do>
</card>
</wml>

 <postfield name="Items" value="$(Items)"/>是传递参数到后台。

接着是servlet

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); 
} 
}

 其实后台只是有拼接了一个wml文件,然后展示出来。不过这个过程要跑通,最起码知道,这个过程这样走是可以的。

你可能感兴趣的:(xml,servlet,MyEclipse,Go,WAP)