Solved

session tracking

Posted on 2014-03-30
1
915 Views
Last Modified: 2014-04-29
Hi,


I was reading about session tracking and cookie example here.

http://www.javatpoint.com/session-tracking-in-servlets
http://www.javatpoint.com/cookies-in-servlet


What is use of session tracking which method is preferable for session tracking aong the 4 methods.

There are 2 types of cookies in servlets.

    Non-persistent cookie
    Persistent cookie

Non-persistent cookie

It is valid for single session only. It is removed each time when user closes the browser.
Persistent cookie

It is valid for multiple session . It is not removed each time when user closes the browser. It is removed only if user logout or signout.

What is difference between persistent and non persisten cookie.

I was thinkingin if user closes browse he automatically logs out. In that case there will all persistent cookies right?

Note: Gmail uses cookie technique for login. If you disable the cookie, gmail won't work

How Gmail uses it. How to test it using my gmail account.
Cookies are maintained at client side
Even though they are maintained at client side is it not server adding cookie to to browser using response as explained below

Introduction to Servlet
What is Servlet Servlet Terminology Servlet API Servlet Interface GenericServlet HttpServlet Servlet Life Cycle Servlet Example How servlet works? War File welcome-file-list Load on startup
Servlet with IDE
servlet in Eclipse servlet in Myeclipse servlet in Netbeans
ServletRequest
Servlet Collaboration
RequestDispacher sendRedirect
ServletConfig
ServletContext
Attribute in Servlet
Session Tracking
Session Techniques 1) Cookies in Servlet Cookies: Login & Logout 2) Hidden Form Field 3) URL Rewriting 4) HttpSession Session: Login & Logout
Event and Listener
Servlet Filter
What is Filter Authentication Filter FilterConfig Useful examples
Servlet Miscellaneous
ServletInputStream ServletOutputStream Annotation Servlet SingleThreadModel SSI
Development
Registration Example Fetching records Improving Performance Uploading file Downloading file Servlet Sending Email Write data to PDF Login Example Writing Image
Servlet Quiz
Servlet Quiz(Part-1) Servlet Quiz(Part-2) Servlet Quiz(Part-3)
space
next>> <<prev
Cookies in Servlet

A cookie is a small piece of information that is persisted between the multiple client requests.

A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number.
How Cookie works

By default, each request is considered as a new request. In cookies technique, we add cookie with response from the servlet. So cookie is stored in the cache of the browser.

To which browser does it add IE or mozilla browser?. Or does it add to all browsers. How to know that

How to delete Cookie?

Let's see the simple code to delete cookie. It is mainly used to logout or signout the user.

    Cookie ck=new Cookie("user","");//deleting value of cookie  
    ck.setMaxAge(0);//changing the maximum age to 0 seconds  
    response.addCookie(ck);//adding cookie in the response  

To delete a cookie do i need to do all above 3 steps like deleting value, changing max age to 0 sec and then adding cookie to response?
Simple example of Servlet Cookies

In this example, we are storing the name of the user in the cookie object and accessing it in another servlet. As we know well that session corresponds to the particular user. So if you access it from too many browsers with different values, you will get the different value.

What author meant by
. So if you access it from too many browsers with different values, you will get the different value.

If servlets residing in different web servers can i still access cookie object as demonstrated in above example in the link.


when i ran this example
I got index.html. I entered name as 'xyz'
i went to servlet1 page which said
'Welcome xyz' with go button.
when i click go button instead of going to servlet2 (with hello xyz)
i got error as below. how to fix this error

HTTP Status 405 - HTTP method GET is not supported by this URL

type Status report

message HTTP method GET is not supported by this URL

description The specified HTTP method is not allowed for the requested resource.
Apache Tomcat/7.0.42
please advise
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
1 Comment
 
LVL 26

Accepted Solution

by:
dpearson earned 500 total points
ID: 39965382
You have about 10 questions here.  How about we just focus on the first few for this question and if you still want more answers to the others you post them as a new question?

>> What is difference between persistent and non persistent cookie.

The difference is just how long before the browser deletes the cookie.
E.g. If you were building a bank app you will want the user to sign in every time they come to the site, so you don't want a persistent cookie.
But for an application like gmail or facebook usually a long lasting cookie is used, just so the user doesn't need to sign in every time they come to the site.

>> How Gmail uses it. How to test it using my gmail account.

If you modify your browser to no longer use cookies, then try to sign in to gmail, you'll get an error.  That's the test.

>> Even though they are maintained at client side is it not server adding cookie to to browser using response

The browser stores the cookie, but it is told to store it (and what value to store) by the server sending it a command in the response to a request.

>> To which browser does it add IE or mozilla browser?. Or does it add to all browsers. How to know that

The cookie is stored in the current browser - the one being used to view the site where the cookie is being used (e.g. gmail in the earlier example).  Each browser has its own separate list of cookies which are completely separate from each other.

I think that's enough questions for this "EE question".

Doug
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now