日期:2014-05-16  浏览次数:20434 次

wml和jsp的后台交互
test2.wml的代码如下:<?xml version="1.0"?>
<!-- created by WAPtor (http://www.waptop.net/) -->
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>

<!-- THIS IS THE FIRST CARD IN THE DECK -->
<card id="MainCard" title="This is a first card">
<p align="center">
  Hello ,what is your name?
  <input name="n" />
  <br/>
  Are you a boy or a girl?
  <select name="s1">
     <option value="am  a  boy">I am  a  boy</option>
     <option value="am a girl">I am a girl</option>
  </select>
  <br/>
  which tutorial do you like?
  <select name="s2"  multiple="true">
  <option value="p1">part1</option>
    <option value="p2">part2</option>
    <option value="p3">part3</option>
    <option value="p4">part4</option>
   
  </select>
  <anchor>
     <go method="get" href="t.jsp">
        <postfield name="post1" value="$(n)"/>
        <postfield name="post2" value="$(s1)"/>
        <postfield name="post3" value="$(n2)"/>  
     </go>
  submit
 
  </anchor>
</p>
</card>
</wml>

t.jsp的代码如下:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 't.jsp' starting page</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">   
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

  </head>
 
  <body>
   <%
     String s1= request.getParameter("post1");
      String s2= request.getParameter("post2");
       String s3= request.getParameter("post3");
       out.println(s1);
      
      
       out.println(s2);
       out.println(s3);
    %>
  </body>
</html>
注意要点:1.$是获取同一个wml下不同card里面的定义的变量。
          2.在NMIT下的模拟器中遇到错误,错误内容是:WML  encoder:charData/Space not allowed in content,其实每一个在card内必须有<p></p>才不会出错。
          3.创建一个tomcat的webapps文件夹中创建一个 名字叫wap的文件夹,将编写好的wml程序和jsp程序放到该文件夹中,然后启动tomcat服务器。然后就可以在winwap中通