

In order to have the project up and running, we’re going to need: In this article, we are going to understand, in a few steps, how to create a Hello World program with Servlets.

However, despite all of that complexities, they are quite simple to use.

Just like init(), it’s up to you override it and implement any type of code that’ll be called only once before the Servlet is really destroyed and discarded by the container.

Once a request arrives, the Servlet object is instantiated (only once per object) and, there, you can do whatever you want to provide the Servlet with important implementation that is going to be useful afterwards. init(): the only responsability of this method is to provide any kind of initialization processing to the Serlvet object.We can divide these three steps into three specific methods: The life cycle of a Servlet always follow the same path: it is first created (initialized by the container), it serves the request (and return a response back) and it finally dies (the server/container will destroy it and clean the resources). XML, JSON or HTML), then the server flushes the same response back to the client (even if something got wrong during this whole path). When the Servlet finishes the processing, the server will return a response object along with all the information of which type of document the client is going to receive (in order to it knowing how to deal with this doc, e.g. Once the request arrives at the server, it translates all of its main information and try to guess which one of its deployed applications is responsible to process, as well as the specific Servlet class to handle the business/data logic. Its job starts when the client creates and sends a request which, in turn, may contain data like the request body itself, cookies, authentication information, headers, etc. Take a look at the following diagram: Client-Server Communication ArchitectureĪll the communication exists between a client (usually a web browser, but it can be any kind of devide that understand HTTP, like pads, smartphone apps, card machines, etc.) and a server (since Servlets are written in Java, they can run in all types of Operating Systems). Servlet Architectureīefore you understand the servlet architecture, you must first address how the HTTP web communication is made upon Servlet’s world.
