如何在GWT中将XML文档发送到客户端?

时间:2013-03-14 09:19:15

标签: java html xml gwt

我有这段代码:

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());
    }

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

2 个答案:

答案 0 :(得分:3)

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

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

进行操作

如果您希望处理xml文件下载以显示某些图表/ etc,则使用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

答案 1 :(得分:1)

很难说“NO”。但它的true

您无法在client方面自行执行此操作。GwtJavascript)无权将内容写入用户驱动器。

您必须制作request。(例如:FileDownLoadServlet)。

无论如何,你必须requestserver