Session Tracking in Servlet/JSP

What is Session?

Answer : A specific time span that user interact with the website, is persistent through out that time span.

Servlet serves the request made by the client and generates the dynamic output. But servlet is not capable enough to remember the last client who made the request by own, because it uses the HTTP protocol, which is a stateless protocol.

To make a session a persist, various approaches could be adapted by servlet like…

  • URL Rewriting (Query String) : Session information is persist by modifying query string. (client side)
  • Hidden Fields : Session information is persist using Hidden Fields in form. (client side)
  • Cookies : Session information is persist using Cookies in via browser in client’s computer. (client side)
  • Http Session : Session inormation is persist using Http Seesion object on server .(server side)

– Ravi Oza


Important Tag in web.xml

Web.xml file is a configuration file in Java web application, it is used to define application wide and servlet/jsp wide settings.

It is a file referred by container on the server to identify Java resources available when requested by client.

Following is the list routine tags available in web.xml file.

  • <web-app>
  • <servlet>
  • <servlet-mapping>
  • <welcome-file-list>

<web-app> : It is the root tag of all the other tags in web.xml file

<servlet> : It is a sub tag of <web-app> tag, use to define servlets name and class, it has two more sub tags which are <servlet-name> and <servlet-class>

It is also used to declare parameter for the respective servlets, using <init-param> followed by two more sub tags, <param-nam> and <param-value>


It is use to describes a pattern used to resolve URLs. This tag is to be written inside <web-app> tag and outside of any <servlet> tag.

It is uses two more sub tags such as <servlet-name> and <url-pattern>


The optional <welcome-file-list> element contains an ordered list of welcome-file elements.

– Ravi Oza


Deployment Descriptor

deployment descriptor (DD) refers to a configuration file for an artifact that is deployed to some container/engine.

In the Java Enterprise Edition, a deployment descriptor describes how a component, module or application (such as a web application or enterprise application) should be deployed.

– Wikipedia

It also contains servlet/jsp wide settings as well as application wide settings for enterprise app of Java.

Another name of deployment decriptor is web.xml, resides in WEB-INF folder in the project hierarchy of Eclipse/NetBeans IDE.

Web.xml is a customized tag file. It allows to configure all the the settings in tag format. Such as, Initialization Parameter, Wel come file list for app, Cookies and Session tags etc.,

-Ravi Oza

%d bloggers like this: