为了账号安全,请及时绑定邮箱和手机立即绑定

ajax请求structs2的action返回json字符串却加上了null() ?

ajax请求structs2的action返回json字符串却加上了null() ?

挥戈小飞侠 2016-06-01 08:41:47
function setIndexComb(){  console.info(1);   $.ajax({       type:"POST",       url:"EnvDataAction_getIndexComb.action",     async:false,    dataType:"json",     success:function(jsonResult){       console.info(2);      console.info(jsonResult);        },         error : function() {         alert("异常!");         }        });         console.info(3);         } public String getIndexComb(){     this.setJsonString("{\"success\":true,\"data\":\"2\"}");     return SUCCESS;  }以上这个请求的返回结果是:null({"success":true,"data":"2"});谁能帮忙解决一下 谢谢了 structs2新手
查看完整描述

1 回答

?
迷失的helloworld

TA贡献6条经验 获得超1个赞

没用过你这种写法,你可以看下官方文档。我给你提供几种方案

  1. 返回结果用stream

public class TextResult extends ActionSupport  {
            private InputStream inputStream;
            public InputStream getInputStream() {
                return inputStream;
            }
            public String execute() throws Exception {
                inputStream = new ByteArrayInputStream("Hello World! This is a text string response from a Struts 2 Action.".getBytes("UTF-8"));
                return SUCCESS;
            }
        }
<action name="text-result" class="actions.TextResult">
    <result type="stream">
        <param name="contentType">text/html</param>
        <param name="inputName">inputStream</param>
    </result>
</action>

对于简单的字符串,手动拼就可以了

2.使用json插件

具体可以查看文档

3.使用gson等一些第三方jar包,配合1

查看完整回答
1 反对 回复 2016-06-11
  • 1 回答
  • 3 关注
  • 1607 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信