• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Questions about session management

 
Ranch Hand
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ??
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic