In the previous section of JSON-Java example you have learned how to create a java class by using JSON classes. Now in this example we will tell you how to use JSON classes for creating Servlet.
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 supported jar files. These are: commons-lang.jar, commons-beanutils.jar, commons-collections.jar, commons-logging.jar, ezmorph.jar and json-lib-2.2.2-jdk15.jar.
Here is the example code of JSONServlet.java as
We have to do corresponding servlet mapping into web.xml as given below:
To run this example follow this step by step procedure:
Ask your questions, our development team will try to give answers to your questions.