猿问

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

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新手

挥戈小飞侠
浏览 1608回答 1
1回答

迷失的helloworld

没用过你这种写法,你可以看下官方文档。我给你提供几种方案返回结果用streampublic 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
随时随地看视频慕课网APP

相关分类

Java
我要回答