O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

But there’s more to a servlet’s life

We stepped into the middle of the servlet’s life, but that still leaves questions: when was the servlet class loaded? When did the servlet’s constructor run? How long does the servlet object live? When should your servlet initialize resources? When should it clean up its resources?

The servlet lifecycle is simple; there’s only one main state—initialized. If the servlet isn’t initialized, then it’s either being initialized (running its constructor or init()method), being destroyed (running its destroy() method), or it simply does not exist.

image with no caption
image with no caption

Your servlet inherits the lifecycle methods

Note

NOTE: do NOT try to memorize all of these now! Just get a feel for how the API works...

image with no caption

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required