In this section, we will develop a Java servlet that will return a list of products as a JSON array. Before building the servlet, we need to create a Java class named Product
. This class is known as a Plain Old Java Object (POJO) as it does not implement any interface or extend any other classes. This class will have many different properties that we are going to use to store the corresponding values.
The value
object of the Product
class has all properties related to a product. The different fields of a product are:
Title: This field contains the title of the product and is of the type
string
. ThegetTitle()
andsetTitle()
methods are two getter and setter methods.Cost: This field contains the pricing of the product and is of the type
integer
. ThegetCost()
andsetCost()
methods are two getter and setter methods.Description: This field contains the information about the product and is of the type
string
. ThegetDescription()
andsetDescription...