WAP网站开发和WWW网站开发大同小异,今天摸索了一天终于写出了第一个wap页面。

WAP网站开发和J2EE网站开发的环境基本一模一样,wml语句嵌入JSP页面即可,服务器采用Tomcat。

index.jsp

<?xmlversion="1.0"encoding="utf-8"?>

<%@ page contentType="text/vnd.wap.wml; charset=utf-8"%>

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>

<head>

<metahttp-equiv="Cache-Control"content="max-age=0"forua="true"/>

<metahttp-equiv="Cache-Control"content="no-cache"/>

</head>

<cardid="Home"title="测试">

<palign="center">

wml2.jsp 尊敬的用户,欢迎您

</p>

<%String uname1=request.getParameter("uname1"); %>

<p><%=uname1 %></p>

<p>

<br><inputtype="text"name="uname1"size="8"value=""/></br>

<br><inputtype="text"name="uname2"size="8"value=""/></br>

<br><inputtype="text"name="uname3"size="8"value=""/></br>

<br><inputtype="text"name="uname4"size="8"value=""/></br>

<anchortitle="提交">提交

<gomethod="post"href="index.jsp"accept-charset="utf-8">

<postfieldname="uname"value="$(uname)"/>

</go>

</anchor>

</p>

</card>

</wml>

PC机的浏览器不能解析wml语言,如果在PC的浏览器通过localhost来访问页面则会弹出下载提示。

我的实例项目名称wheat

本机IP地址 192.168.24.207

端口:8080

使用Android手机通过wifi接入局域网,在浏览器里面输入 http://192.168.24.207:8080/wheat即可访问wap页面。


index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"><html><head><meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" /><meta name="viewport" content="width=device-width; initial-scale=1.3; minimum-scale=1.0; maximum-scale=2.0" /><meta name="apple-mobile-web-app-capable" content="yes" /><meta http-equiv="Expires" content="0" /><meta http-equiv="Pragma" content="no-cache" /><meta http-equiv="Cache-Control" content="no-cache,no-store,max-age=0,s-maxage=0,must-revalidate" /><link href="css/style.css" rel="stylesheet" type="text/css" /><%@ taglib uri="/struts-tags" prefix="s"%><title>农业信息采集系统</title></head><body> <div id="header"> <jsp:include page="header.jsp"></jsp:include> </div> <div> 欢迎您, <s:property value="#session.user.username" /> <br> ${sessionScope.user.username } </div> <div id="footer"> <jsp:include page="footer.jsp"></jsp:include> </div></body></html>