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
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 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.
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.
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.