Creating the index.html page

For the sake of simplicity, this page will just have a button invoke life cycle. When you will click this button it will call LifeCycleServlet (which is mapped according to the entry in web.xml file). 

HTML




<html>
    <form action="LifeCycleServlet">
        <input type="submit" value="invoke life cycle servlet">
    </form>
</html>


The name of the Servlet is given in action attribute of form tag to which the request will be send on clicking the button, in this case FirstServlet

Starting with first Servlet Application

To get started with Servlets, let’s first start with a simple Servlet application i.e LifeCycle application, that will demonstrate the implementation of the init(), service() and destroy() methods.
First of all it is important to understand that if we are developing any Servlet application, it will handle some client’s request so, whenever we talk about Servlets we need to develop a index.html page (can be any other name also) which will request a particular Servlet to handle the request made by the client (in this case index.html page).
To be simple, lets first describe the steps to develop the LifeCycle application : 

  • Creating the index.html page
  • Creating the LifeCycle Servlet
  • Creating deployment descriptor
     

Similar Reads

Creating the index.html page

For the sake of simplicity, this page will just have a button invoke life cycle. When you will click this button it will call LifeCycleServlet (which is mapped according to the entry in web.xml file)....

Creating the Servlet (FirstServlet)

...

Creating deployment descriptor(web.xml)

Now, its time to create the LifeCycleServlet which implements init(), service() and destroy() methods to demonstrate the lifecycle of a Servlet....

How to run the above program ?

...