wml与服务器交互 开发和服务器交互功能

现在很多人开发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://localhost:8080/ewap/wapservlet method=get><postfield name=Items value=$(Items)/></go></do></card> </wml>用户可以从列表中选择Item,通过无线网络传输给服务器后Servlet通过request.getParameter()方法得到用户的选择并发送给用户,servlet的代码如下: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); }}

12在本页阅读全文 本文导航 第1页: 首页 第2页: web.xml中配置

全球传输最远、最快的USB 有源光纤数据线面世 « 上一篇下一篇 » 从谷歌光纤分析国内光纤器件的前景
相关文章
回到顶部