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:
To run this example follow this step by step procedure:
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial