• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Questions about session management

 
Adam Zedan
Ranch Hand
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going over session management using the java API and I came down to two examples

one example is from the Head First Servlets and JSP this uses session.isNew
Example is


and the other example i came across is which does not use .isNew method but instead depends on a variable value in the session :



1- I wanted to know which method is better the .isNew one or the other one.
2- Since both the above methods use the java API for server management.. do people still write custom cookies to manage their session ??
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you said, the first one will always return true, unless you call it with a 'false' parameter. While the second one checks if it's the first visit from the client. These do different things.

As for who using cookies for session management, i am not surr. The API actually uses cookies achieve session management.
 
Adam Zedan
Ranch Hand
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bosun Bello wrote:As you said, the first one will always return true, unless you call it with a 'false' parameter. While the second one checks if it's the first visit from the client. These do different things.

As for who using cookies for session management, i am not sure. The API actually uses cookies achieve session management.

I agree that the second one is a counter which basically counts the no of times a user visits that specific address.
But i believe it can also be used for the same purpose as the first code.
If the value of access count > 0 then that means the user is not a new user.


 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
accesscount can easily be nulled by another servlet while not influencing the session. isNew method will only return true if there was no session before the corresponding call to getSession.

Checking whether a session already existed can be done using either isNew() or getSession(false) and a null check.
 
Jeff Ishar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you can use this



Programmer do stuff in different ways so what you need to find out is what minimize the code and easy to read. And always try to reuse the code which is already done for you unless you want extra functionality like in accessCounter.

Hope it helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic