想要天天向上,就要懂得享受学习。图老师为大家推荐应用Java技术开发WAP应用程序,精彩的内容需要你们用心的阅读。还在等什么快点来看看吧!
【 tulaoshi.com - 编程语言 】
我们还是采用Tomcat作为web服务器,如果你对如何使用tomcat还不熟悉请参考相关资料。通常我们开发WAP应用程序的时候都是手写wml脚本,其实我们可以借助java的Servlet/jsp技术开发WAP应用程序。通常我都是使用Lomboz插件在eclipse的环境下写servlet/jsp文件的。先看下面的waptest.jsp文件和WapServlet.java文件 <?xml version="1.0"?>
这两个文件实现的功能是一样的,显示服务器当前的时间。我们的web.xml的内容如下:
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<%
response.setContentType("text/vnd.wap.wml");
out.println("<wml>");
out.println("<card title="MobileDate">");
out.println(" <p align="center">");
out.println("Date and Time Service<br/>");
out.println("Date is: "+ new java.util.Date());
out.println("</p>");
out.println("</card>");
out.println("</wml>");
%>
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("<?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="MobileDate">");
out.println(" <p align="center">");
out.println("Date and Time Service<br/>");
out.println("Date is: " + new java.util.Date());
out.println("</p>");
out.println("</card>");
out.println("</wml>");
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
doGet(request,response);
}
}
<?xml version="1.0" ?>
使用Lomboz我们可以很方便的把这个应用程序发布到tomcat的webapps目录,通过WinWap我们可以直接通过下面两个URL访问到他们
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>WapServlet</servlet-name>
<servlet-calss>com.j2medev.mingjava.WapServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WapServlet</servlet-name>
<url-pattern>/wapservlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
</web-app>
http://localhost:8088/wap/wapservlet
http://localhost:8088/wap/waptest.jsp
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
来源:http://www.tulaoshi.com/n/20160219/1599281.html
看过《应用Java技术开发WAP应用程序》的人还看了以下文章 更多>>