简体   繁体   English

从Action到JsonArray的返回类型到具有多个JSONArray对象的JSP?

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

I have a JSONArray Which has 2 JSONArray Objects which i am returning from Action to JSP. 我有一个JSONArray,它有2个JSONArray对象,我从Action返回到JSP。 But In JSP, it throws an error in the response received from Action. 但是在JSP中,它会在从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 JSP代码

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 问题是我没有从Action获得正确的响应,因此jsp中的错误警告popsup在获取数据时出现错误

I dont find any issues with the JSONArray Objects that you have returned from Action To JSP . 我没有发现从Action To JSP返回的JSONArray对象的任何问题 Try Returning the JSONArrayObject through 尝试通过返回JSONArrayObject

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 . 如果仍然无法正常工作,我觉得有一些垃圾数据从Action转移到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. 尝试debuggingPrinting操作方法中的System.out.println ,这可能会让您知道JSONArrayObject中从Action转移到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. 如果你正在使用像Struts / Springs这样的框架( 你应该提到它 ),请检查控件是否已传递给控制器​​类,如果控件没有通过。 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. 从控件传递的XML文件( 例如:Struts 2中的Struts.xml )到Action类应该存在一些问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM