Solved

session tracking

Posted on 2014-03-30
1
967 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 27

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.
Suggested Courses

752 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