The mood example application is comprised of three components: mood.web.MoodServlet, mood.web.TimeOfDayFilter, and mood.web.SimpleServletListener.
MoodServlet, the presentation layer of the application, displays Duke’s mood in a graphic, based on the time of day. The @WebServlet annotation specifies the URL pattern:
@WebServlet("/report")
public class MoodServlet extends HttpServlet {
...
TimeOfDayFilter sets an initialization parameter indicating that Duke is awake:
@WebFilter(filterName = "TimeOfDayFilter",
urlPatterns = {"/*"},
initParams = {
@WebInitParam(name = "mood", value = "awake")})
public class TimeOfDayFilter implements Filter {
...
The filter calls the doFilter method, which contains a switch statement that sets Duke’s mood based on the current time.
SimpleServletListener logs changes in the servlet’s lifecycle. The log entries appear in the server log.