我们还是采用Tomcat作为web,如果你对如何使用tomcat还不熟悉请参考Tomcat入门指南。通常我们开发WAP应用程序的时候都是手写wml脚本,其实我们可以借助java的Servlet/jsp技术开发WAP应用程序。通常我都是使用Lomboz插件在eclipse的环境下写servlet/jsp文件的。先看下面的waptest.jsp文件和WapServlet.java文件
"">
<%
response.setContentType("text/vnd.wap.wml");
out.println("
");
out.println("");
out.println(" ");
out.println("Date and Time Service
");
out.println("Date is: "+ new java.util.Date());
out.println("
");
out.println("");
out.println("");
%>
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
{
response.setContentType("text/vnd.wap.wml");
PrintWriter out = response.getWriter();
out.println("");
out.println(" out.println("\"\">");
out.println("
");
out.println("");
out.println(" ");
out.println("Date and Time Service
");
out.println("Date is: " + new java.util.Date());
out.println("
");
out.println("");
out.println("");
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
doGet(request,response);
}
}
这两个文件实现的功能是一样的,显示当前的时间。我们的web.xml的内容如下:
WapServlet
com.j2medev.mingjava.WapServlet
WapServlet
/wapservlet
index.jsp
404
/error.jsp
使用Lomboz我们可以很方便的把这个应用程序发布到tomcat的webapps目录,通过WinWap我们可以直接通过下面两个URL访问到他们
【责编:admin】
--------------------next---------------------