Java 如何在GWT中向客户端发送XML文档?

Java 如何在GWT中向客户端发送XML文档?,java,html,xml,gwt,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"); node

我有一段代码:

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());
    }
如何将此文档发送到客户端进行下载而不将其存储在目录中?

很难说“
”。但它的
正确

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

您必须发出
请求
(例如:)

无论如何,你必须向
服务器发出
请求

很难说“
”。但它是
真的

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

您必须发出
请求
(例如:)


无论如何,您必须向
服务器发出
请求
,这实际上取决于您希望如何在客户端处理它

如果您希望为用户显示下载的文件弹出窗口,请按照

如果您希望处理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

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

如果您希望为用户显示下载的文件弹出窗口,请按照

如果您希望处理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