Never confuse education with intelligence, you can have a PhD and still be an idiot.
- Richard Feynman -

Java-Web:Servlet serving XML or JSON

From Juneday education
Jump to: navigation, search

Introduction and description

This chapter has a lecture showing how you could write a small Servlet which serves data in different formats.

The purpose of this chapter, is to show you how a client could request the same data from the same Servlet but specify what format the client wants the data to be represented in. This showcases how to send GET parameters (parameters as part of the URL) and how the Servlet, in its doGet() method, can read GET parameters in order to make decisions.

There are two versions of this lecture. The first shows how to produce the JSON formatted data response using the javax.json package (part of the Java Enterprise API). It also has a video lecture.

The second lectures shows the exact same thing, but uses org.json for the production of the JSON response. This second lecture doesn't yet have a video version.

If you want to create a Servlet capable of serving application/json and plan to use either of the APIs for creating JSON, you can choose the version of this lecture that fits your needs. Or see both if you want to be able to create JSON using either javax.json or org.json.


Videos and lecture slides

This lecture comes in two flavors, the first using javax.json for json production, and the second using org.json.

For javax.json you need some JAR with the Java EE libraries (javax.json in particular).

For org.json you need a JAR with org.json. In the source code repository, you can find how to get these JARs.

Using javax.json for the JSON production

Using org.json for the JSON production (slides only)


External links

  • []

TODO: more external links (see pdf for a few)

Source code


Up next: Exercises!

« PreviousBook TOCNext »