Friday 17 February 2012
J2EE: SERVLET: Session Tracking in Servlets using Interface HttpSession
Do you like this Article?
- 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.
Example:
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
}
Subscribe to:
Post Comments
(
Atom
)
Popular Posts
-
public - public means everyone can access it.That means it's in global scope. As, main method is called by JVM [ Java Virtual Machine...
-
throw is used to throw an exception in a program, explicitly . Whereas, throws is included in the method's declaration part, wi...
-
Singleton in one of the most popular yet controversial design pattern, in the world of object oriented programming. It's one of t...
-
Web Container / Servlet Container / Servlet Engine : In J2EE Architecture , a web container (also known as servlet container or ser...
-
Program compiles. But at runtime throws an error “NoSuchMethodError”.
-
Vector : It's synchronized. It's slower than ArrayList. It's generally used in ...
-
doGet(): protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, java.io.IOException – is a met...
-
In Java Programming Language , we must declare a variable name and type, before using it. The data type of a variable defines the th...
4 Responses to “ J2EE: SERVLET: Session Tracking in Servlets using Interface HttpSession ”
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
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
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
25 April 2022 at 13:38
Thanks for one marvelous posting! I truly enjoyed reading it, you might be a great author. I will make sure to bookmark your blog and will come back in the future. I want to encourage that you continue your great job.
python internship | web development internship |internship for mechanical engineering students |mechanical engineering internships |java training in chennai |internship for 1st year engineering students |online internships for cse students |online internship for engineering students |internship for ece students|data science internships |
Post a Comment