概要:
如何在struts2的action中返回數據(普通字符串、xml數據島字符串等)給ajax核心中的XMLHttpRequest對象(即模仿傳統jsp頁(yè)面的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
<action name="BaseInfo" class="controller.hosp.BaseInfoAction">
<result></result>
</action>ok~~~~~~~~!
補充:實(shí)習后發(fā)覺(jué)這樣更簡(jiǎn)單
getResponse().getWriter().write("your output String");
struts.xml配置連result標簽都不用寫(xiě)了
聯(lián)系客服