当前位置: 代码迷 >> Ajax >> ajax回来InputStream
  详细解决方案

ajax回来InputStream

热度:302   发布时间:2012-07-05 07:59:18.0
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;
}
  相关解决方案