• Post Reply Bookmark Topic Watch Topic
  • New Topic

Display Json data on Jsp page from servlet  RSS feed

 
simer singh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Iam trying to implement Json in my application using servlets and Jsp. I have set data in Json Object in my servlet class like

JSONObject object=new JSONObject();
object.put("name","simerpreet");
object.put("Max.Marks",new Integer(100));
object.put("Min.Marks",new Double(40));
object.put("Scored",new Double(66.67));
object.put("nickname","simer");

String output=object.toString();
request.setAttribute("output",output);

When i print <%=request.getAttribute("output")%> out on jsp page is
{"name":"simerpreet","Max.Marks":100,"Min.Marks":40,"Scored":66.67,"nickname":"simer"}

now how can i iterate values on my jsp from servlet page to fetch data like key value pair or correct me if am wrong ....



Thanks,
Simer
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

The JSONObject class probably has a method that returns all the individual attribute names; check its javadocs.

If this is the class you're using, then JSONOBject.getNames(request.getAttribute("output")) should do the trick.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!