//new to java /
Introduction to RESTful
Web Services (Part 2)
Handle the JSON response format with an HTML5 Web client.
MAX BONBHEL
JAVA IN ACTION
PHOTOGRAPH BY
ALLEN MCINNIS/GETTY IMAGES
In Part 1 of this three-part series, I showed how to quickly create and deploy a Java Platform,
Enterprise Edition (Java EE) application that uses Representational
State Transfer (REST) Web services with NetBeans. The application
developed in Part 1
will be the basis for
this second article on
implementing new
functionalities.
Now, in Part 2, we
will see in detail how to
use JavaScript Object
Notation (JSON) to
handle the response
returned to the client. We will also add a
small dose of HTML5,
JavaScript, and Ajax to
call the Web services,
store the information
locally, and display the
information later.
Note: The complete source
code for the application designed
in this article can be downloaded
here.
JSON and HTML5
JSON is a human-readable data
format based on JavaScript tech-
nology. The structure of JSON is
easier to parse and extend than
traditional XML. JSON format is
used by most applications that
provide Web services
through Web clients.
HTML5 is the next
generation of HTML.
It provides new features that are necessary for modern Web
applications. It also
standardizes many
features of commonly
available browser
technologies that Web
developers have been
using for years to create rich Web applications without the need
for plug-ins.
HTML5 is designed to be cross-
platform, and it does not require
a specific operating system. The
only thing we need is a modern
Web browser, such as the latest
version of Firefox, Opera, Safari,
or Chrome.
HTML5 provides
very cool
functionalities
for storing the
data in your browser
and accessing
the data with
JavaScript after the
page is loaded.
Let’s Code and Test the JSON
Representation
To begin, we will modify the re-
sources to ensure that the server
returns a response in the format
that we want (JSON).
ABOUT US
blog
See how to use JavaScript Object Notation with
HTML5 to store, retrieve, and display information.