日期:2014-05-16 浏览次数:20715 次
response.setContentType("text/xml; charset=utf-8"); response.setHeader("Cache-Control", "no-cache"); PrintWriter out = response.getWriter(); out.println("<RESPONSE>"); out.println("<page>" + page + "</page>"); out.println("</RESPONSE>"); out.close();]
public static void response(HttpServletResponse response, String[][] xmlArgs) throws Exception { response.setContentType("text/xml; charset=utf-8"); response.setHeader("Cache-Control", "no-cache"); PrintWriter out = response.getWriter(); out.println("<RESPONSE>"); for (int i = 0; i < xmlArgs.length; i++) { if ("~@begin@~".equals(xmlArgs[i][1])) { out.println("<" + xmlArgs[i][0] + ">"); } else if ("~@end@~".equals(xmlArgs[i][1])) { out.println("</" + xmlArgs[i][0] + ">"); } else { out.println("<" + xmlArgs[i][0] + ">" + xmlArgs[i][1] + "</" + xmlArgs[i][0] + ">"); } } out.println("</RESPONSE>"); out.close(); }
String[][] newsXml = new String[5 * rowCot + 4][2]; newsXml[0][0] = "page"; newsXml[0][1] = Integer.toString(page); newsXml[1][0] = "pageSize"; newsXml[1][1] = Integer.toString(pageSize); newsXml[2][0] = "pageCot"; ewsXml[2][1] = Integer.toString(pageCot); newsXml[3][0] = "rowCot"; newsXml[3][1] = Integer.toString(rowCot); int xmlIdx = 3; // 这里循环列出 while(true) { newsXml[++xmlIdx][0] = "news"; newsXml[xmlIdx][1] = "~@begin@~"; newsXml[++xmlIdx][0] = "id"; newsXml[xmlIdx][1] = Integer.toString(news.getId()); newsXml[++xmlIdx][0] = "top"; newsXml[xmlIdx][1] = Integer.toString(news.getTop()); newsXml[++xmlIdx][0] = "title"; newsXml[xmlIdx][1] = title; newsXml[++xmlIdx][0] = "news"; newsXml[xmlIdx][1] = "~@end@~"; } XmlUtil.response(response, newsXml);
PrintWriter out = response.getWriter(); out.println("<RESPONSE>"); out.println("<page>" + page + "</page>"); out.println("</RESPONSE>"); out.close();]
------解决方案--------------------
直接传出news的recordset
然后利用field.name来做标签 值就是field.value并且可以由rs来获取page,pagecount等信息。
------解决方案--------------------
要不你就直接从servlet返回json
然后前台用js动态加入 也可以
------解决方案--------------------