Return Type for JsonArray from Action to JSP having multiple JSONArray Objects?

sTg

I have a JSONArray Which has 2 JSONArray Objects which i am returning from Action to JSP. But In JSP, it throws an error in the response received from Action. I am unable to track the issue however. Request you to please guide.

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 issue is i am not getting the correct response from Action and hence the error alert popsup in jsp Error occured while fetching data

Gerald Baretto

I dont find any issues with the JSONArray Objects that you have returned from Action To JSP. Try Returning the JSONArrayObject through

out.println(masterObject.toString);

If still this is not working i feel like there is some junk data that is getting transferred from Action To JSP. Try debugging or Printing The System.out.println in your action method which may possibly let you know the data in your JSONArrayObject that is getting transferred from Action to JSP. If still issues? . If you are using some framework like Struts/Springs(Which you should have mentioned), check if the control is getting passed to your controller class, if the control is not getting passed. There should be some issue with your XML File from where the control passes(Eg: Struts.xml in case of Struts 2) to the Action class.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Return Type for JsonArray from Action to JSP having multiple JSONArray Objects?

From Dev

JSONArray from JSONArray in java

From Dev

JSONArray from JSONArray in java

From Dev

How to loop a JSONArray passed from javascript in jsp?

From Dev

JSONArray JSP Ajax Jquery

From Dev

highlight multiple dateranges from jsonArray datepicker (jquery)

From Dev

JsonArray return null value

From Dev

JsonArray return null value

From Dev

JSONArray in JSONArray

From Dev

How to get java objects from JSONArray url using Jackson in Android

From Dev

How to remove duplicate and sort objects from JSONArray using Java

From Dev

from JSONArray to List<CustomClass>

From Dev

Create JsonArray from List

From Dev

Get values from a JSONArray

From Dev

Getting a JSONObject from a JSONArray?

From Dev

create JSONArray from JSONObject

From Dev

Get JSONArray from JSONObject

From Dev

Type conversion from phparray to jsonarray and sending back in response

From Dev

Type conversion from phparray to jsonarray and sending back in response

From Dev

How to retrieve response from multiple url using Jsonarray in android

From Dev

parsing JSONArray with multiple values in android

From Dev

How to output jsonArray with html elements into JSP

From Dev

How can I access JSONArray elements in JSP

From Dev

Remove quote from the JSONArray output

From Dev

How to create Cursor from JSONArray?

From Dev

Get the specific value from JSONarray

From Dev

Remove quote from the JSONArray output

From Dev

Remove JSONobject from JSONarray in Android

From Dev

extract jsonarray from xml string