【问题标题】:How do I send an XML document to the client in GWT?如何在 GWT 中向客户端发送 XML 文档?
【发布时间】:2013-06-12 20:24:05
【问题描述】:

我有这段代码:

public void generateXML(DynamicForm form) {
        Document doc = XMLParser.createDocument();

        Element root = doc.createElement("root");
        doc.appendChild(root);

        Element node1 = doc.createElement("node1");
        node1.setAttribute("attribute","test");
        node1.appendChild(doc.createTextNode("my value"));
        doc.appendChild(node1);

        Element node2 = doc.createElement("node2");
        node2.setAttribute("attribute","anothertest");
        doc.appendChild(node2);
        System.out.println(doc.toString());
    }

如何将此文档发送到客户端进行下载而不将其存储在目录中?

【问题讨论】:

    标签: java html xml gwt


    【解决方案1】:

    这实际上取决于您希望在客户端如何处理它。

    如果您希望为用户显示下载的文件弹出窗口,请关注How can a user download a file in client side (Google Web Toolkit)

    如果您希望处理 xml 文件下载以显示一些图表/等,请使用带有 gwt xml 处理的请求构建器概念。

    Reference 1 - https://developers.google.com/web-toolkit/doc/latest/DevGuideServerCommunication#DevGuideHttpRequests
    Reference 2 - https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasics#DevGuideXML
    Reference 3 - https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsXML
    

    【讨论】:

      【解决方案2】:

      很难说“NO”。但它是true

      您不能在client 端本身执行此操作。Gwt(Javascript) 没有将内容写入用户驱动器的权限。

      您必须创建一个request。(例如:FileDownLoadServlet)。

      无论如何,您必须将request 发送到server

      【讨论】:

        猜你喜欢
        • 2011-10-17
        • 1970-01-01
        • 2011-02-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-27
        相关资源
        最近更新 更多