Creating deployment descriptor(web.xml)
As discussed in other posts about web.xml file we will just proceed to the creation of it in this article.
XML
<? xml version="1.0" encoding=" UTF = 8 "?> < web-app > < servlet > < servlet-name >LifeCycleServlet</ servlet-name > < servlet-class >LifeCycleServlet</ servlet-class > </ servlet > < servlet-mapping > < servlet-name >LifeCycleServlet</ servlet-name > < url-pattern >/LifeCycleServlet</ url-pattern > </ servlet-mapping > < session-config > < session-timeout > 30 </ session-config > </ web-app > |
To know the working and use of the above web.xml file its recommended to read the next post.
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