在servlet中查询数据库得到一个数据集,怎么样将该数据集打包为一个XML文件传递给调用servlet的客户端??
谢谢各位

解决方案 »

  1.   

    我都是自己写代码组合.
    一般使用DOM4J
      

  2.   

    也许网上有第三方的包来实现,不过也可以自己写的,得到数据集,构造一个xml文件
      

  3.   

    org.jdom.contrib.input.ResultSetBuilder aa = new org.jdom.contrib.input.ResultSetBuilder(ResultSet rs);
        aa.build().toString();
      

  4.   

    /*
     * Created on 2005-8-14
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    package com.motel168.ws;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;/**
     * @author qiyadeng
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    public class CreateXML extends HttpServlet { /**
     * Constructor of the object.
     */
    public CreateXML() {
    super();
    } /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
    super.destroy(); // Just puts "destroy" string in log
    // Put your code here
    } /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { response.setContentType("text/xml;charset=GB2312");
    PrintWriter out = response.getWriter();
    out.println("<?xml version=\"1.0\" encoding=\"GB2312\"?>");
    out.println("<root>");
    out.println("<user>");
    out.println("<username>qiya</username>");
    out.println("<password>qiya</password>");
    out.println("</user>");
    out.println("<user>");
    out.println("<username>qiyadeng</username>");
    out.println("<password>qiyadeng</password>");
    out.println("</user>");
    out.println("</root>");
    out.flush();
    out.close();} /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { } /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occure
     */
    public void init() throws ServletException {
    // Put your code here
    }}
      

  5.   

    這個是用生硬的方法生成xml的代碼
    從數據庫裏讀齣來在處理下就好暸
      

  6.   

    qiyadeng(流浪小子) 
    哥们
    你这个方法我也会
    这个不是太好吧
    不过还是给你100分
    到结帐的时候来取下面各位来个让我动心的
      

  7.   

    晕,找个书看一下JAXP编程就可以了