More Tutorials| Bioinformatics| Open Source| Photoshop| Questions? | Software Development
 

JSON-JSP example

In the previous section of JSON-Servlet example you have learned how to create a servlet class by using JSON classes.

JSON-JSP example

                         

In the previous section of JSON-Servlet example you have learned how to create a servlet class by using JSON classes. Now in this example we will tell you how to use JSON to use it into JSP pages.

In this example we have created  an object of JSONArray and then we have added elements into this array by using the method add(). To have functionality of JSON in your application you must have JSON-lib and its supporting jar files as well. These are: commons-lang.jar, commons-beanutils.jar, commons-collections.jar, commons-logging.jar, ezmorph.jar and json-lib-2.2.2-jdk15.jar. To get string values of array object we have used getString(index int) method of JSONArray. It returns string value of that array object's index.

Here is the example code of JSON-JSPExample.jsp as follows:


JSON-JSPExample.jsp
 

<%page language="java" import="net.sf.json.JSONArray" %>
 
 <%
  JSONArray arrayObj=new JSONArray();
   arrayObj.add("MCA");
   arrayObj.add("Amit Kumar");
   arrayObj.add("19-12-1986");
   arrayObj.add(24);
   arrayObj.add("Scored");
   arrayObj.add(new Double(66.67));
%>
<h2>Array Object is =></h2> <%=arrayObj%>
<br><hr>
<%  for(int i=0;i<arrayObj.size();i++){  %>
          <%=arrayObj.getString(i)%>
<%
  }
%>


To run this example follow this step by step procedure:

  • create a JSON-JSPExample.jsp file and 
  • place it into WEB-INF directory
  • Download JSONLibraries and place it into Tomcat's lib directory
  • Start Tomcat Webserver and type
    http://localhost:8080/JSON/JSON-JSPExample.jsp  into browser's address bar you will have following output on your browser.

Output:

 

Download JSON-JSP Project code

 

                         

» View all related tutorials
Related Tags: java javascript c arrays json array tutorials script object io objects parse sed ip vi tutorial ria this message create

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.