日期:2014-05-16  浏览次数:20429 次

struts2返回json和几种方式

一、response对象返回

???? ??response.setContentType("text/html");

?? ? ?PrintWriter out = response.getWriter();

?? ? ?out.println("json");

?? ? ?out.flush();

?? ? ?return?null;

?? ? 输入结果: json


二、通过struts返回stream来输出

?? ?action代码

?? ? public?class TextResult?extends?ActionSupport {

?? ? ? ? ? ?private?InputStream inputStream;

?? ? ? ? ? ?public?InputStream getInputStream() {

?? ? ? ? ? ? ? return?inputStream;?

?? ? ? ? ? ?}?

?? ? ? ? ?publicString?execute()?throws?Exception {

?? ? ? ? ? ? ? inputStream =?new?StringBufferInputStream("json");

?? ? ? ? ?return?SUCCESS; }?