ajax实际应用(2)服务器端将数据以XML格式传回

 List listRet = null;
    listRet = mgmt.queryTwo(tmp_realname);
    //***********返回XML*********//
    HttpServletResponse response=this.getResponse();
    response.setContentType("text/xml;charset=gb2312");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    StringBuffer str=null;
    try
    {
     PrintWriter out = response.getWriter();
     out.println("<?xml version=/"1.0/" encoding=/"gb2312/"?>");
     out.println("<data>");
     selfTerminalDt dt=null;
     for (int i = 0; i < listRet.size(); i++)
     {
      dt=(selfTerminalDt)listRet.get(i);
      str = new StringBuffer("<row");
      
      str.append(" ChannelId=/"").append(dt.getChannelId()).append("/"");
      str.append(" ChannelName=/"").append(dt.getChannelName()).append("/"");
      
      str.append("/>");
      out.println(str);
     }
     out.println("</data>");
    }
    catch (Exception e)
    {
     e.printStackTrace();
    }
    ///******************************************///

你可能感兴趣的:(ajax实际应用(2)服务器端将数据以XML格式传回)