Context and Servlet Initialization Parameters 1. Overview Servlets are plain Java classes that run in a servlet container. HTTP servlets (a specific type of servlet) are first class citizens in Java web applications.  The API of HTTP servlets is aimed at handling HTTP requests through the typical request-processing-response cycle, implemented… Continue Reading context-servlet-initialization-param

Returning a JSON Response from a Servlet 1. Introduction In this quick tutorial, we’ll create a small web application and explore how to return a JSON response from a Servlet. 2. Maven For our web application, we’ll include javax.servlet-api and Gson dependencies in our pom.xml: <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>${javax.servlet.version}</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId>… Continue Reading servlet-json-response

An Intro to the Spring DispatcherServlet 1. Introduction Simply put, in the Front Controller design pattern, a single controller is responsible for directing incoming HttpRequests to all of an application’s other controllers and handlers. Spring’s DispatcherServlet implements this pattern and is, therefore, responsible for correctly coordinating the HttpRequests to their… Continue Reading spring-dispatcherservlet

web.xml vs Initializer with Spring 1. Overview In this article we’ll cover three different approaches of configuring a DispatcherServlet available in recent versions of the Spring Framework: We’ll start with an XML configuration and a web.xml file Then we’ll migrate the Servlet declaration from the web.xml file to Java config,… Continue Reading spring-xml-vs-java-config

A Guide to the Front Controller Pattern in Java 1. Overview In this tutorial we’ll be digging deeper into the Front Controller Pattern, part of the Enterprise Patterns as defined in Martin Fowler‘s book “Patterns of Enterprise Application Architecture”. Front Controller is defined as “a controller that handles all requests… Continue Reading java-front-controller-pattern