在struts2的Action中返回Ajax显示需要的信息

来源:百度文库 编辑:神马文学网 时间:2024/04/19 19:52:12
概要:
如何在struts2的action中返回数据(普通字符串、xml数据岛字符串等)给ajax核心中的XMLHttpRequest对象(即模仿传统jsp页面的ajax交互)
方法:
public String execute() throws Exception {
String str="xxoohuai";
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=GBK");//解决中文乱码
PrintStream out = new PrintStream(response.getOutputStream());//获取out输出对象
out.println(str);
return null;//这里返回的是null
}
配置struts.xml



ok~~~~~~~~!
补充:实习后发觉这样更简单
getResponse().getWriter().write("your output String");
struts.xml配置连result标签都不用写了