'how to read json array from servlet to jsp

JSONObject,jsonarray cannot be resolved to a type

servlet:

    while(rs.next())
    {
    JsonObject jo=new JsonObject();
    jo.put("id",rs.getString(1));
    jo.put("sname",rs.getString(2));
    jo.put("gender",rs.getString(3));
    jo.put("address",rs.getString(4));
    jo.put("gmail",rs.getString(5));
    ja.add(jo);
    }
    request.setAttribute("jarray", ja);
            request.getRequestDispatcher("staff.jsp").forward(request, 
            response);

jsp:

   <% JsonArray ja= (JsonArray)request.getAttribute("jarray");
    for (int i=0;i<ja.size();i++) 
{
JsonObject rec = (JsonObject) ja.get(i);
System.out.print("<tr><td>"+rec.getInteger("id")+"</td> 
    <td>"+rec.getString("name")+"</td><td>"+rec.getString("gender")+"</td> 
    <td>"+rec.getString("address")+"</td><td>"+rec.getString("gmail")+" 
     </td></tr>");}

how can i read the json array in jsp.



Solution 1:[1]

Its typo error

Wrong:

JsonArray ja= (JsonArray)request.getAttribute("jarray");

Correct:

JSONArray ja= (JSONArray)request.getAttribute("jarray");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 procrastinator