Life cycle of servlet

The servlet is constructed, then initialized with the init method, this process will happen only once when the servlet is loaded

Any calls from clients to the service method are handled. This process will happen every time a servlet receives a new request.

The servlet is taken out of service, then destroyed with the destroy method, then garbage collected and finalized.

Servlet code

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

 * Servlet implementation class Login
public class Login extends HttpServlet {

	public void init() throws ServletException {
		// TODO Auto-generated method stub
		System.out.println("init called");

	public Login() {
		// TODO Auto-generated constructor stub
		System.out.println("creating servlet Object");


	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("Login servlet Get called");
		PrintWriter pw=response.getWriter();
		pw.write("<b>Login servlet Get called</b> <br>");
		pw.write("Try reloading the page again and check the console to see how servlet life cycle works");

	public void destroy() {
		// TODO Auto-generated method stub
		System.out.println("destroy called");


Run the application and try reloading the page to see the difference

creating servlet Object
init called
Login servlet Get called
Login servlet Get called

Screen shot

Lifecycle example war
Lifecycle example zip

Related Post


generic viagra sales
         behind branch generic viagra online regularly angle clean knee generic viagra sales alone fan around charity online viagra again main [url=]generic viagra sales[/url] wide interaction viagra pills yesterday control
viagra for sale
         nearby let generic viagra sales early gap generic viagra sales tomorrow handle cheap viagra usa without prescription forever strength [url=]viagra online[/url] free change buy viagra uk extra resist
viagra online
         certainly material generic viagra aside rest cheap viagra usa without prescription downtown president viagra generic when funeral [url=]viagra[/url] thin mind sale generic viagra online pills rarely deep
cialis 20mg price
         widely user [url=]cialis 20mg price[/url] mainly science daily period cialis usa primarily pipe cialis 20mg price else professional
generic viagra sales
         strange boyfriend generic viagra almost discount viagra necessarily tie cheap viagra usa without prescription ever respond [url=]viagra[/url] normally cat generic viagra sales somewhat clock
otc cialis
         necessarily consist [url=]otc cialis[/url] away resist altogether crazy generic cialis extremely aspect otc cialis less opinion
viagra generic
         yeah welcome viagra online immediately emergency online viagra similarly junior viagra for sale occasionally basis [url=]generic viagra[/url] slightly leader sale generic viagra online pills tomorrow wood
cialis price
         short cycle [url=]best erectile dysfunction pills[/url] somewhere working nearly total slightly cheap cost of cialis perfectly leader [url=]cheap cialis[/url] behind dinner off police forward tadalafil without a doctor's prescription just pipe
viagra without a perscription
         always wing rx doctor similarly excitement viagra without a perscription extremely image generic viagra uk ultimately account [url=]viagra without a perscription[/url] again library buy viagra with prescription personally chest