Chinaunix首页 | 论坛 | 博客
  • 博客访问: 30467276
  • 博文数量: 708
  • 博客积分: 12163
  • 博客等级: 上将
  • 技术积分: 8240
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-04 20:59
文章分类

全部博文(708)

分类: Java

2009-11-16 14:44:31

--- servlet----

package com.ajax;

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 AjaxServlet extends HttpServlet {

String[][] hebeiArr;
String[][] beijingArr;

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
   System.out.println("ajaxServlet onload .....");
   hebeiArr = new String[3][2];
   beijingArr = new String[3][2];
   String[][] tmpArr = null;
   hebeiArr[0][0] = "11";
   hebeiArr[0][1] = "石家庄";
   hebeiArr[1][0] = "12";
   hebeiArr[1][1] = "廊坊";
   hebeiArr[2][0] = "13";
   hebeiArr[2][1] = "秦皇岛";
   beijingArr[0][0] = "01";
   beijingArr[0][1] = "昌平";
   beijingArr[1][0] = "02";
   beijingArr[1][1] = "通州";
   beijingArr[2][0] = "03";
   beijingArr[2][1] = "大兴";
   String id = req.getParameter("id");
   if(id.equals("hb")){
    tmpArr = hebeiArr;
   } else if(id.equals("bj")){
    tmpArr = beijingArr;
   }
   StringBuffer sb = new StringBuffer();
   sb.append("");
   System.out.println(tmpArr.length);
   for(int i=0; i    sb.append(""+tmpArr[i][0]+""+tmpArr[i][1]+"");
   }
   sb.append("
");
   resp.setContentType("text/xml");
   resp.setHeader("Cache-Control", "no-cache");
   resp.setCharacterEncoding("utf-8");
   PrintWriter out = resp.getWriter();
   out.print(sb.toString());
   System.out.println(sb.toString());
   out.close();
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
   this.doGet(req, resp);
}

}
-----------------------

----- jsp-------

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%

%>










  
  


   
  

   
  





---------------------

---------web.xml---------


xmlns=""
xmlns:xsi=""
xsi:schemaLocation="
">

    index.jsp


AjaxServlet
com.ajax.AjaxServlet



AjaxServlet
/servlet/AjaxServlet


----------------------

阅读(1487) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~