-
Book Overview & Buying
-
Table Of Contents
Java Web Internals
By :
Let's create a small example of an application that uses SimpleWebContainer in action. In this case, we will build a class that extends our SimpleServlet to randomly generate a temperature value between 25 and 28 degrees Celsius. Basically, we will have a /weather path that returns a JSON object with the following structure:
{
"temperature": 25.35
}
In addition, we will create a static HTML page with CSS style and a JavaScript file. This JavaScript file will consume a URL to dynamically fill a section of the page. Therefore, our SimpleWebContainer manages and delivers both static and dynamic content.
This static content (HTML page, CSS file, and JS script) is available in the STATIC_FOLDER folder, and the servlet that randomly generates the temperature measurement is available in the WEB_FOLDER folder.
First, we will define our servlet. Since it will return a specific object, we will initially create our WeatherDTO (which is a record that contains the...