Return type for JsonArray from Action for JSP with multiple JSONArray objects?

I have a JSONArray that has 2 JSONArray objects that I am returning from Action to JSP. But in JSP, it causes an error in the response received from Action. However, I can not track this problem. Please refer to the manual.

Action Code:

try
        {
            Class<EmployeePojo> objClass= EmployeePojo.class;
            Field[] methods = objClass.getDeclaredFields();
            columnJsonArrayObject=FormatDatesAndMethods.methodsData(methods);                                                       
            masterDataJsonArrayObject=new JSONArray();
            String query="from EmployeePojo";
            employeeList= factoryImplObject.searchByQuery(query);   
            if(employeeList!=null)
            {
                for(int j=0;j<methods.length;j++)
                {
                    for(int i=0;i<employeeList.size();i++)
                    {
                        masterDataColumnValuesJsonObject=new JSONObject();
                        if((employeeList.get(i)).getWorkshopId()!=null)
                        {
                            masterDataColumnValuesJsonObject.put(""+methods[0].getName()+"", employeeList.get(i).getId());  
                        }
                        else
                        {
                            masterDataColumnValuesJsonObject.put(""+methods[0].getName()+"", "");   
                        }
                        if((employeeList.get(i)).getWorkshopName()!=null)
                        {
                            masterDataColumnValuesJsonObject.put(""+methods[1].getName()+"", employeeList.get(i).getName());    
                        }
                        else
                        {
                            masterDataColumnValuesJsonObject.put(""+methods[1].getName()+"", "");   
                        }
                        if((employeeList.get(i)).getDivId()!=null)
                        {
                            masterDataColumnValuesJsonObject.put(""+methods[2].getName()+"", employeeList.get(i).getJivId());   
                        }
                        else
                        {
                            masterDataColumnValuesJsonObject.put(""+methods[2].getName()+"", "");   
                        }
                        if((employeeList.get(i)).getHqId()!=null)
                        {
                            masterDataColumnValuesJsonObject.put(""+methods[3].getName()+"", employeeList.get(i).getPlace());   
                        }
                        else
                        {
                            masterDataColumnValuesJsonObject.put(""+methods[3].getName()+"", "");   
                        }   
                        masterDataColumnValuesJsonObject.put("Old", "old");
                        masterDataJsonArrayObject.put(masterDataColumnValuesJsonObject);
                    }
                    break;
                }
                masterObject.put(0,columnJsonArrayObject);
                masterObject.put(1, masterDataJsonArrayObject);             
                if(masterObject!=null)
                {
                    out.write(masterObject.toString);   
                }
            }
        }
        catch(Exception e)
        {
        }

JSP Code

function values()
{
    var values=
    {
        url:"metaData.do?actionMethod=loadMasterData",
        handleAs:'json',
        content:parameter,
        load: function(response)
        {

        alert("working");

        },
        error: function(data)
        {
            alert("Error occured while fetching data");
        },
        timeout: 3000,
        sync: true                              
    };
    dojo.xhrPost(values);
}

The problem is that I am not getting the correct response from Action and, therefore, a pop-up window warning about an error in jsp Error while extracting data

+4
source share
1 answer

JSONArray, Action To JSP. JSONArrayObject

out.println(masterObject.toString);

, , Action To JSP. debugging Printing System.out.println , , , JSONArrayObject, Action JSP. ?, - , Struts/Springs (, ), , , . XML , ( Eg: Struts.xml Struts 2) Action.

+1

All Articles