Solved

session tracking

Posted on 2014-03-30
1
942 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 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jar file executable 12 59
tomcat not starting 6 69
eclipse buid path vs tomcat lib path 10 34
String array comparison 4 38
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

828 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