Q:

Manage ArrayList in jquery and print exit in jsp

what i wanted to do is use jquery to get data from the databases and show it in the jsp pages.
In my jsp:
<input onclick="getPlatform('${item.string1}')"type="radio" id="${item.string1}" name="tab-group-1" checked>

in my .js:
$.ajax({
    type: "POST",
    url: "Controller?operation=GetPlatforms",
    data: dataString,
    dataType: "json",
    //if received a response from the server
    success: function(data, textStatus, jqXHR) {
        //our platform was correct so we have some information to display
        if (data.success) {
            $.each(data.PlatformInfo, function() {
                $("#ajaxResponsePlatforms").html("");
                $("#ajaxResponsePlatforms").append("value: " + data.PlatformInfo.name);
            });
        }
        //display error message
        else {
            $("#ajaxResponsePlatforms").html("<div><b>Country code is Invalid!</b></div>");
        }
    },

the server output is:
value of JsonElement: [{"name":"PC"},{"name":"Servers"}]
value of myObj: {"success":true,"PlatformInfo":[{"name":"PC"},{"name":"Servers"}]}

and the result in my JSP pages is:
value: undefined

Code to build Json response:
String technology = request.getParameter("technology");
            System.out.println("Test " + technology);
            PrintWriter out = response.getWriter();
            response.setContentType("text/html");
            response.setHeader("Cache-control", "no-cache, no-store");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Expires", "-1");

            response.setHeader("Access-Control-Allow-Origin", "*");
            response.setHeader("Access-Control-Allow-Methods", "POST");
            response.setHeader("Access-Control-Allow-Headers", "Content-Type");
            response.setHeader("Access-Control-Max-Age", "86400");

            Gson gson = new Gson();
            JsonObject myObj = new JsonObject();

            BACENGQueryDatabases PlatformData = new BACENGQueryDatabases();
            ArrayList PlatformInfo = PlatformData.GetPlatform(technology);
            JsonElement platformObj = gson.toJsonTree(PlatformInfo);

            System.out.println("JsonElement: " + platformObj);

            if (PlatformInfo.isEmpty()) {
                myObj.addProperty("success", false);
                System.out.println("Array empty");
            } else {
                myObj.addProperty("success", true);
                System.out.println("Array full");
            }
            System.out.println("value json " + platformObj);
            myObj.add("PlatformInfo", platformObj);
            out.println(myObj.toString());
            System.out.println(" myObj: " + myObj.toString());
            out.close();

It's happenign since I want to do get the result as ArraList form, however if instead Array I use a single String object it is working fine.
how can use ArayList and jquery.apped method?

A:

if you use $.each on data.PlatformInfo you shoud use what's iterated on inside the callback, not data.PlatformInfo which is a list (and has no .name), something like this:
$.each(data.PlatformInfo, function(i, e) { // i = index, e = element
    // are you sure you want to: $("#ajaxResponsePlatforms").html("");
    $("#ajaxResponsePlatforms").append("value: " + e.name);
});

Also note that setting html content to "" inside the loop is probably not what you want, you probably want that before the $.each.
Demo: JSFiddle

