Back to Top

Friday, 17 February 2012

J2EE: SERVLET: Session Tracking in Servlets using Interface HttpSession

  • Session tracking in Servlets is done by using Interface HttpSession. It helps to identify a client throughout many page requests or visiting a website and to store details about that client.
  • Whenever a request arrives, it checks for the preexisting session object, to fetch details of the client from there, else, if its first request from a new client, its simple creates a session object for that client. These session objects are simple java objects.
  • HttpSession contains various methods to handle session object. HttpSession object lives in the server, and it automatically associated with the requester by internal mechanism like cookies or URL-rewriting
  • Whenever an application invokes or removes an object from a session, the session checks whether the object implemented the interface HttpSessionBindingListener or not. If yes, the servlet informs the object that it has been bounded to the session, if not, notifies unbound from the session. This alert goes after the binding methods complete.


HttpSession session = request.getSession(true);
/*  here, ‘request.getSession(true)’ - returns the current session associated with this request, or if the request does not have a session, creates one. */
     ClientDetails client_details = (ClientDetails)session. getAttribute("client_details");
if(client_details != null) {
//that means, existing client, can do something with the client_details
} else {
//create new client_details and store into the session

Anijit Sarkar

6 Responses to “ J2EE: SERVLET: Session Tracking in Servlets using Interface HttpSession ”

Java Experience said...
23 January 2013 at 22:57

readers would be interested to note that it is a bad practice to store data in the session of a user as session attributes as it increases load on the application and is vulnerable. for more details see session tracking in java ee

Naviya Nair said...
24 October 2016 at 15:27

I have read your blog its very attractive and impressive. I like it your blog.

Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai

Online Java Training Java 8 Online Training | Java J2EE Online Training | JavaEE Training Institute in Chennai Java Training Institutes

Java Training Institutes in Chennai Java Training in Chennai

john kevin said...
16 April 2018 at 14:57

Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
Best Java Training Institute Chennai

CIIT Noida said...
23 April 2018 at 17:11

CIIT Noida provides Best MCA Courses in Noida based on the current

IT industry standards that help students to get high paying jobs in Top MNCs. CIIT provides Best MCA Training in Noida, Greater Noida, and Ghaziabad.

CIIT is one of the trusted MCA training institutes in Noida providing practical knowledge and 100% job assistance with basic as well as advanced

level MCA subjects. CIITN is the best MCA college in Noida, greater noida, ghaziabad, delhi, gurgaon regoin.

At CIIT MCA classes in Noida is conducted by subject experts corporate professionals with 9+ years of experience in managing real-time and live

projects. Sofracle Nano Specialized MCA classes Noida is the perfect blend of academic learning and practical sessions to provide maximum exposure to

students that transform an average student into a corporate professional whom companies prefer to hire.

Best MCA College in Noida

sumant kumar said...
29 August 2018 at 18:16

I found best article.thank you for sharing useful info.
web programming tutorial

pavankanna said...
8 October 2018 at 15:41

I respect your undertakings since it passes on the message of what you are endeavoring to state. It's an outstanding strength to make even the person who doesn't consider the subject could organized to grasp the subject. Your web diaries are sensible and likewise excessively portrayed. I should need to examine a dependably expanding number of fascinating articles from your blog. Keep Sharing
Tableau online training in India, Australia
Online Tableau training in Singapore, Malaysia

Post a Comment

Popular Posts

All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar
blog links Web Directory Academics Blogs