Home › Forums › Guriddo jqGrid JS › Help › Obtaining JSON object from struts action response
Hello,
I get an empty grid when trying to obtain a json object from struts action method.
Making use of the following
Hello,
Finally got it to work
.
Made slight modifications to the existing code:
Struts Action:
1) Earlier was returning to an empty jsp page with no specific code. Now returning null.
2) Using the write method of the jsonObj to write the response data.
The action method now looks like the following:
public ActionForward getJSONData(ActionMapping mapping, ActionForm form,
aarati said:
Hello,
Finally got it to work
.
Made slight modifications to the existing code:
Struts Action:
1) Earlier was returning to an empty jsp page with no specific code. Now returning null.
2) Using the write method of the jsonObj to write the response data.
The action method now looks like the following:
public ActionForward getJSONData(ActionMapping mapping, ActionForm form,
Hi Kiran,
Which version of struts are you using? What is the
aarati said:
Hello,
Finally got it to work
.
Made slight modifications to the existing code:
Struts Action:
1) Earlier was returning to an empty jsp page with no specific code. Now returning null.
2) Using the write method of the jsonObj to write the response data.
The action method now looks like the following:
public ActionForward getJSONData(ActionMapping mapping, ActionForm form,
Hi aarati,
I am new here, I will appreciate if you can send me the src code of a working example using :
1) Struts 1.2
2) JQGrid 3.8.2
3) JQuery 1.4.4
my email is : majidnakit@yahoo.com
Thanks lot.
moin_mkhan said:
aarati said:
Hello,
Finally got it to work
.
Made slight modifications to the existing code:
Struts Action:
1) Earlier was returning to an empty jsp page with no specific code. Now returning null.
2) Using the write method of the jsonObj to write the response data.
The action method now looks like the following:
public ActionForward getJSONData(ActionMapping mapping, ActionForm form,
kirangentlebreeze1987 said:
aarati said:
Hello,
Finally got it to work
.
Made slight modifications to the existing code:
Struts Action:
1) Earlier was returning to an empty jsp page with no specific code. Now returning null.
2) Using the write method of the jsonObj to write the response data.
The action method now looks like the following:
public ActionForward getJSONData(ActionMapping mapping, ActionForm form,
aarati said:
Hello,
I get an empty grid when trying to obtain a json object from struts action method.
Making use of the following
hiii aarti would you explain how to use jquery , json with java & jsp in struts 1.2 ? Please clarrify your code and what is the use url an how to automaically create jquery grid in jsp.
Thanks a zillion Arati! That works like magic! 
What are the java libraries (jar) required for json?
I tried the above with json-lib-2.2.2-jdk15.jar and I am getting “java.lang.NoClassDefFoundError: net.sf.ezmorph.Morpher” error.
aarati said:
Hello,
Finally got it to work
.
Made slight modifications to the existing code:
Struts Action:
1) Earlier was returning to an empty jsp page with no specific code. Now returning null.
2) Using the write method of the jsonObj to write the response data.
The action method now looks like the following:
public ActionForward getJSONData(ActionMapping mapping, ActionForm form,
vsendhil said:What are the java libraries (jar) required for json?
I tried the above with json-lib-2.2.2-jdk15.jar and I am getting “java.lang.NoClassDefFoundError: net.sf.ezmorph.Morpher” error.
I downloaded the JARs and fixed this
@kirangentlebreeze1987 said:
aarati said:
Hello,Finally got it to work
.
Made slight modifications to the existing code:
Struts Action:
1) Earlier was returning to an empty jsp page with no specific code. Now returning null.
2) Using the write method of the jsonObj to write the response data.
The action method now looks like the following:
public ActionForward getJSONData(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {…
…
 JSONObject jsonObj = createJSONTestData();
System.out.println(“Final JSON OBj: ” + jsonObj.toString());Â
jsonObj.write(response.getWriter());
return null;
 }Â
JSP:
JSP Code to populate the grid is shown below:
$(document).ready(function(){
$.ajax(
   {
      type: “POST”,
      url:’  /TestJSON/testAction.do?method=getJSONData’,
      data: “”,
      dataType: “json”,
      success: function(result)
      {
           alert(“success”);
           alert(“result: ” + result.total);
           jQuery(“#list10”).jqGrid({
            url:’  /TestJSON/testAction.do?method=getJSONData’,
               datatype: ‘json’,
               mtype: ‘POST’,
               colNames:,
        colModel:[
            {name:’id’,index:’id’, id:’name’,width:90},
            {name:’invdate’,index:’invdate’, width:120},
            {name:’invname’,index:’invname’, width:200}
    ],
               pager: jQuery(‘#pager1’),
               rowNum: 5,
               rowList: [5, 10, 20, 50],
               viewrecords: true
           })
      },
      error: function(x, e)
      {
           alert(“errorddd ” + x.readyState + ” “+ x.status +” “+ e);
           if (x.readyState == 4) {
            var response = x.responseText;
            alert(response);
           }
      }
   });
setTimeout(function() {$(“#list10”).jqGrid(‘setGridParam’,{datatype:’json’}); },50);
});
 If any one faces any problem with the above mentioned implementation please post a reply to this topic.
Regards,
Aarati
i do have some problem populating a json object values to my gridÂ
can you help me???
Hi aarati,
Can u provide me full code which is mentioned above.I need it very urgently Pls reply fast.
Thanks,
anees.iny
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top