这样调用Struts2 的Aciton: tree.loadXML("/dhtmlxTree.action?userid=<%=id%>");
在Action中这样写:
public voidjdomDhtmlxTree() throws Exception {
HttpServletResponse response = ServletActionContext.getResponse();
......
Document xmlDocument = new Document(tree);
org.jdom.output.Format format = org.jdom.output.Format.getCompactFormat();
format.setEncoding("gb2312");
format.setIndent(" ");
XMLOutputter outputter = new XMLOutputter(format);
try {
response.setContentType("text/xml; charset=gb2312");
response.setHeader("Cache-Control", "no-cache");
outputter.output(xmlDocument, response.getWriter());
}
catch (IOException e) {
e.printStackTrace();
}
}
struts.xml中这样配置
<action name="dhtmlxTree" class="dhtmlxTree" method="jdomDhtmlxTree">
</action>
这样执行没有报错,不知道会不会有什么问题?请大家帮忙,分析一下,谢谢!
问题补充:
这是struts2的特征之一。
gaoran2008, 能不能说的清楚一点,能告诉我在Struts2的参考中哪有提到吗,我没找到,谢谢!
这是很常见的用法,不想有返回值,自然会将调用方法写成void类型。
Struts2/webwork 设计的初衷就是要实现一个[color=red]简单而且灵活[/color]的框架,没有很严格的使用限制,文档对这些过于细化的问题也不会说太多。
应该不会有问题,我现在也是这样做的,也没出现问题。
action返回也是回到你想要去的地方。
这是struts2的特征之一。