Following answer is applicable irrespective of the language and platform used. Before we enter into session tracking, following things should be understood.
A session is a conversation between the server and a client. A conversation consists series of continuous request and response.
When there is a series of continuous request and response from a same client to a server, the server cannot identify from which client it is getting requests. Because HTTP is a stateless protocol.
When there is a need to maintain the conversational state, session tracking is needed. For example, in a shopping cart application a client keeps on adding items into his cart using multiple requests. When every request is made, the server should identify in which client’s cart the item is to be added. So in this scenario, there is a certain need for session tracking.
Solution is, when a client makes a request it should introduce itself by providing unique identifier every time. There are five different methods to achieve this.
The first four methods are traditionally used for session tracking in all the server-side technologies. The session tracking API method is provided by the underlying technology (java servlet or PHP or likewise). Session tracking API is built on top of the first four methods.
Users can be authorized to use the web application in different ways. Basic concept is that the user will provide username and password to login to the application. Based on that the user can be identified and the session can be maintained.
<INPUT TYPE=”hidden” NAME=”technology” VALUE=”servlet”>
Hidden fields like the above can be inserted in the webpages and information can be sent to the server for session tracking. These fields are not visible directly to the user, but can be viewed using view source option from the browsers. This type doesn’t need any special configuration from the browser of server and by default available to use for session tracking. This cannot be used for session tracking when the conversation included static resources lik html pages.
Original URL: http://server:port/servlet/ServletName
Rewritten URL: http://server:port/servlet/ServletName?sessionid=7456
When a request is made, additional parameter is appended with the url. In general added additional parameter will be sessionid or sometimes the userid. It will suffice to track the session. This type of session tracking doesn’t need any special support from the browser. Disadvantage is, implementing this type of session tracking is tedious. We need to keep track of the parameter as a chain link until the conversation completes and also should make sure that, the parameter doesn’t clash with other application parameters.
Cookies are the mostly used technology for session tracking. Cookie is a key value pair of information, sent by the server to the browser. This should be saved by the browser in its space in the client computer. Whenever the browser sends a request to that server it sends the cookie along with it. Then the server can identify the client using the cookie.
In java, following is the source code snippet to create a cookie:
Cookie cookie = new Cookie(“userID”, “7456”);
Session tracking is easy to implement and maintain using the cookies. Disadvantage is that, the users can opt to disable cookies using their browser preferences. In such case, the browser will not save the cookie at client computer and session tracking fails.
Session tracking API is built on top of the first four methods. This is inorder to help the developer to minimize the overhead of session tracking. This type of session tracking is provided by the underlying technology. Lets take the java servlet example. Then, the servlet container manages the session tracking task and the user need not do it explicitly using the java servlets. This is the best of all methods, because all the management and errors related to session tracking will be taken care of by the container itself.
Every client of the server will be mapped with a javax.servlet.http.HttpSession object. Java servlets can use the session object to store and retrieve java objects across the session. Session tracking is at the best when it is implemented using session tracking api.
Comments are closed for "Session Tracking Methods".
[…] after all, software is all about mimicking real life. In a previous article I discussed about methods used for session tracking. It has fundamental information about what a session is and how to manage it. At the end of that […]
nice article i love it
Pls read “conversation” in place of “conversion” above in the paragraph “What is a session?”.
Hey, Joe, Please correct me if I am wrong.
Thanks Paras for pointing the spelling mistake. I have rectified that.
Joe. I like this article that u have
presented.My humble request, Try to
nice one i like it
spelling of alongwith not alogwith in topic cookies
its better to refer ur experiences before going to attend interviews. its a fabulous website which includes not only matter but also the terrific doubts which are posted by the fans, thank u
i like your formate . it is very good and simple to understood.
@ananya – thanks, corrected.
@Vinoth – I will try to include soon. :-)
oh…very nice. simple understandble language..very nice article
nice…. commmands.. it easy to apply the progrms..
very nice explanation……thanx.also,i liked the design of your web page.
Very good article… simple understandble language … nice one…… simple .. good.
Sir please add the coding how add & get session in servlet
Excellent article: clear and understandable.
simple and understandable sir..plz give the code to add cookie
Nice, easy language…
really a helpful material, it helped me great in understanding concept.
nice article….can you post more core java articles it may be useful for beginers
Its really good…..
I studied for exam through this blog only…….
Lot of thanks………
soooo good help full to me
thanks a lot
That was extremely useful and very simple explained. Thanks
thanks for the tutorial on session in java.
Iyt help me a lot to understand briefly about session tracking
Brief n precised explanation about session tracking… Gud one!!!
WOW excellent article.
very useful for beginner.
Thank u very much for sharing your experience
It is really nice format and easy to uderstand …and help me brief Session tracking API using servlet ….
i am waiting for reply
very nice… thank you for explaining in detail
Thanks for clear delivering of Good info. about the Session Tracking
Its really very clear to understand,
In the cookie section u should also mention about the server side cookie mantainance(i.e. how server know that this cookie is meant for a particular user?).
I like your article.
it’s very easy to understand,
try to prefer this one, may be it give an help to you…
KRS RAJASEKHAR ON January 18th..
good explanation but i need examples also
Joe, your presentation skills are quite good.. thanks for this stuff..
Good One But It will be helpful if mention the Disadvantage of First Method
nice explanation for beginners of java
VeRy Good Explaination..It will be the best if you can give a simple example for ech type…
Really its very easy to understand..
Really its very easy to understand..
thank u very much…………….
Nice Article..Very good to understand and pratice for freshers who does not have any knowldge on sessionn
helloo sir..U r article abt SESSION TRACKING was very informative…am doing my BTECH Final yr proj on session tracking…i need ur guidence for that.
plz help me sir..
can you give me ur contact number or ur email-id.
hayeeee…. its a good article……
Can you please elaborate on the 5th way – session API. i think it needs little more explanation.
Anyways nice blog, very informative n of all, very simple
Thanku so much!!!
all your blogs are really clear and understandable…
thank you so much for sharing!!
very much clear!!! nice work…….
its realy very good, and easy to understand
tanku so much
its really good,it helped me a lot thankq
Useful content.. It is very precise and clear…
its really simple and awesome…….. thanks
but sir, there are only 3 questions covered on Collections, you know it sir Java Collections is the heart of Java………. i kindly request you post some more on Collections and the difference between them.
Thank you, once again your site is a bible for Java guys…
will you maintain small example concept wise it is very good.
ok Anyway It’s a nice nice blog.
it’s really good..simply to understood…
thank you very much
Its really good one.. I like your articles.
very easy and simple language to understand!!
Thanks a lot!!
simple and understandable.
On index of this blog i think this post must be in JSP or SERVLET section.
I like your blogs, that’s why i suggest this change.
Point me if i am wrong.
its really nice….
its really nice….
It’s a nice article and very easy to understand. You presented it using simple language.
if example is presented simply superb
thanks ,its very to under stand for students
Nice web design
Nice web design
it is very nice……
thanks a lot
thank’s sir !!!!!!!!
its easy to understand
its easy to understand
you are doing good for itians.
it really to understand concepts from beginning.
thanks a lot sir, can u give more concepts of java like this it will be useful for us
Thank u very much sir,It is very simple and easy for understanding. can You Give me other java concepts also like this it will more useful for my career sir.
Evey time I get conceptual understanding with vast meaning.
sir,in the above 5 methods which is the best one to implement in realtime
thanx for a wonderful article…!
Nice preparation. One suggestion from my side. Could you explain briefly about session management using Session API. It could be great.
one suggestion from my side can u include both Hibernate and Spring.
Very nice and useful article,Joe
sir, This is a spectacular article. i loved it… awesome
All your articles are simply awesomeeee..:-) Easy to understand..
Thanks a lot..
Brevity is the soul of wit! And this article is of that kind! Very simple,very clear and very very effective!
@ajit: dude.. improve ya english!!
u r awesome joe!!
I am in awe of your lucid explanation for every single topic (i have come across!).
ya its very useful to the beginers……thanks
for your information …it helps me a lot…!
I like the simplicity in the explanation!!!
thanks, its very easy language explain,everything know about session tracking
once again thanks very much
thanks, its very easy language
explain,everything know about session tracking
thanks thanks thanks
Plz explain wit examples..specially URL Rewriting..
Whats the purpose of session tracking?
HTTP protocol is state less protocol in order to maintain the state we will use session tracking mechanism
for example :
i need to buy a book in online shopping
and a pen first i bayed a book the HTTP request holds the book now again i wanna buy a pen now the previous request will be replaced by new request that is pen in order to maintain two requests we use session tracking mechanism
Mainly we have 4 types of session tracking Mechanism:Http Session
hidden form fields
in the hidden field method of sessin tracking
This cannot be used for session tracking when the conversation included static resources like html pages.
what is this mean? could you please explain this?
It’s really super
plz Give me details about Session scope.Existing session information.if we add any values to session object.then those are not thread safe.how to overcome this problem.sir please give information with practicallly what u r saying.
I am new to java, Please guide me programing as well as coding with more examples.
Thanks in Advance.
what if a browser doesn’t accept cookies i.e if cookies are disabled
good one this is very understable manner artical very useful and effective
Very nice article. Thank you Joe..
its nice artical…..easy way
Need more programmatic explaination. Rest good as usual. Thanks
i want example on session Tracking methods
Superb…simple explanation..i love it…
Easy to understand but need some more deep explanation
very simply written article…….
i like this topic .it is easy to understand……thanks
Please kindly let me know how to track the session by using SessionTracking API
Nice article.. till now I didnt have clear idea on the session Mngt. Now I have it.
Thanks for taking time to write such a good articles.
This session tracking is only possible for a single server. How would you track a user session when there are clusters available and every request doesn’t land in the same server all the time?
Sir, I want to get the session of one servlet on another servlet. For ex:-
If I log in a user and a page is displayed then I click on account info,I should get the username again..
How can I do that….
Please help me out…
I like very much please provide programs for allthese things
can u explain with example using session tracking API
hey joy please add the explanation of web.xml used in servlet.
ananya content is important and not spelling
very nice article …thanks
Its Very Good Article.Helped But Still need Some more . Shall I get session Object again with the help of any of the following session.getId(); , creationdate() or anything else.
I am depending on other site for some processes in my project.There I am lossing my session values when Url changes . How to retrack the session values back .
That is a nice tutorial.Explained in depth. Me too want your articles on struts spring and hibernate as these frameworks are a lot in demand now-a-days.Thank you.