From the course: Java EE: Servlets and JavaServer Pages (JSP)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Understanding the servlet life cycle

Understanding the servlet life cycle

From the course: Java EE: Servlets and JavaServer Pages (JSP)

Start my 1-month free trial

Understanding the servlet life cycle

- Now let us talk about the servlet life cycle. All the servlet classes that we have created so far: login, servlet, and any other that you may see in your project, all of them have extended HttpServlet and have either overridden the doGet or the doPost method so that actions are taken accordingly. And whenever we hit the request from the client, the control automatically came inside one of the doGet or the doPost methods. But in Java, whenever you want to invoke a method of any class, you need an object of that class and then a reference variable to call that method. But we have never instantiated any of our Servlet classes nor did we call any of these methods ourselves. So what is this entire thing that goes behind the scenes where this is getting worked out automatically? That is exactly what we need to understand as a part of the servlet life cycle. The servlet life cycle firstly is entirely managed by the server container. In our case it is TomCat, or it could be any other…

Contents