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.
Checking whether a session already existed can be done using either isNew() or getSession(false) and a null check.