Javatpoint Logo
Javatpoint Logo


JSON(JavaScript Object Notation) is a language independent format for data. It is similar to XML as XML uses tags JSON uses Object-Literal notation of JavaScript.


Creating a source of JSON data of Stock Exchange example:

We have implemented stock price class and refresh watch list method as:

Creating Servlet

In this we create a servlet file for stock quotes in JSON format. Following are the steps for creating servlet are:

1) Create a Servlet

  1. In the Package Explorer, select the client
  2. In Eclipse, open the New Java Class wizard (File > New > Class).
GWT Json 1

2) Under Package, change the name from .client to .server

  1. Under name, enter JsonStockData.
  2. Eclipse will create a package for the server-side code and a stub for the JsonStockData class.
GWT Json 2

3) Replace the stub with following code:

Including Server Side Code

GWT consists of in build servlet container Jetty which hosts the servlet that generates stock data in JSON format. Steps for including server side code in GWT are:

  1. Edit the following code under StockWatcher/war/WEB-INF/web.xml

Retrieving JSON Data

  1. Debug StockExchange in development mode.
    1. At this point, the stock data is still coming from the client-side code.
  2. Test the stock quote server.
    1. Ensure that the development mode code server is running and pass stock codes to the servlet URL http://localhost:8888/stockexchange/stockPrices?q=ABC+DEF
  3. The servlet generates an array of simulated stock data encoded in JSON format.
GWT Json 3
Next TopicGWT XML

Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA