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

ajax返回InputStream
jsp页面
jQuery.post(
    	"test1.action",
    	{"param":param},
    	function(data){
              //dosomething in success.
              if(data.success == "success"){
              }
  	},
    	"json"
    );

struts2的配置
<package name="jsonDefault" namespace="" extends="json-default">
        <action name="test*" method="test{1}" class="***">
           <result name="success" type="stream">
                <param name="contentType">text/html</param>
                <param name="inputStream">inputStream</param>
            </result>
        	</action>

java
private transient InputStream inputStream;
public String test1(){
StringBuilder sb = new StringBuilder();
sb.append("{'result':'success'}");
inputStream=new ByteArrayInputStream(sb.toString().getBytes("utf-8"));
return SUCCESS;
}