How to check whether a cookie has been set on previous visit?

In a java web application,I want to check whether a user who signs in is a returning user. How can I check if there is already a cookie that has been set on earlier login.


Set cookie when user performs log-in:

Cookie c = new Cookie("visit", "old")
c.setMaxAge(3600*24*365*1000); // 1 year (for example)
response.addCookie(new Cookie("visit", "old"));

Now you can check this cookie when user with new session comes to the system: request.getCookies(), then iterates over returned array and find "your" cookie. If cookie exists this is "old" user otherwise the new one.

On HttpServletRequest you have a getCookies() method that will give you an array of the cookies the client is sending with his request.

Need Your Help

x-editable with meteor textarea no line breaks and date timezone issue

timezone meteor x-editable

I'm currently trying to work in bootstrap x-editable to my meteor application. I'm using the atmosphere package for this: I'm having a ...

Gather all Feature objects returned by Async methods

spring asynchronous aop aspectj future

I am using Spring Framework stack, and I'm trying to realise the following feature.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.