UrbanPro
true

Take Engineering Diploma Tuition from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Session Tracking In Java Servlets

D Subba Rao
07/08/2017 0 0

Session Tracking:

HTTP is a stateless protocol. Each request is independent of the previous one. However, in some applications, it is necessary to save state information so that information can be collected from several interactions between a browser and a server. Sessions provide such a mechanism.

  1. Http Session
  2. Cookies

1. Http Session:

  • It is used for saving client details at server-side.
  • Session object can be created by calling the getSession( ); method.
  • For retreiving the values from the session object, we can use the getAttribute( );

                      HttpSession   hs = req.getSession( );

                      hs.setAttribute(“sname”,name);

                      String s = (String) hs.getAttribute(sname);

  • It creates the new session id for each client and the session object is available until the session time expires.

2. Cookies:

  • It is used to save the client details at the client-side itself.
  • It is also used for client validations.
  • The Cookie class encapsulates a cookie. A cookie is stored on a client and contains state information. Cookies are valuable for tracking user activities.
  • For example, assume that a user visits an online store. A cookie can save the user’s name, address, and other information. The user does not need to enter this data each time he or she visits the store.
  • A servlet can write a cookie to a user’s machine via the addCookie( ) method of the HttpServletResponse The data for that cookie is then included in the header of the HTTP response that is sent to the browser.
  • Cookie is a class, by creating cookie object, it allows to store the client details:

                      Cookie  c1 = new  Cookie(“sname”, name);

                      Cookie c2 = new  Cookie(“address”, hyd);

                      res.addCookie(c1);

                      res.addCookie(c2);

  • To retreive values from the cookie object:

                      Cookie[ ] = req.getCookies( );

                      pw.println(c[0].getName( ));

                      pw.println(c[0].getValue( ));

0 Dislike
Follow 2

Please Enter a comment

Submit

Other Lessons for You

What is a Programming Language
What is a Language? Language is a communication system of human. What is a programming Language? A programming Language is a formal constructed language design to communicate...

How do i get best Campus / Off Campus Placement?
Companies are looking for Skilled Freshers. So build your technical skills while doing MCA / BTech / BCA / BSc (IT or CS) into below areas- 1. Strong your programming & debugging skills ...

Tips of learning Java Language/Other Programming Languages
1.You should know the basic concept: If we talk about programming languages so basic concept are same in all the high level languages. So you should know the basic concept firstly then you can easily understand...
I

ICreative Solution

0 0
0

Class and Objects in Java
Class is a template or a blueprint which is used to describe an object. On other hand Object is a reference of a class which follows all the stuff written inside the class. How about taking the whole tour in the following video

What Would Be Life Cycle Of A Fresher After Campus In An IT Company?
1. Basic Technical Training: Since freshers are not subject matter experts so gone through 3 - 6 months basic technical training within Organization. 2. Technical Assessment: HR sends freshers to various...

Looking for Engineering Diploma Tuition ?

Learn from Best Tutors on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Engineering Diploma Tuition Classes?

The best tutors for Engineering Diploma Tuition Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Take Engineering Diploma Tuition with the Best Tutors

The best Tutors for Engineering Diploma Tuition Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more