This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session tracking

 
ashu goel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
What I want to do is that when a person logs in on my site I want to provide him with the date he last logged in..
How can that be done???
I am using JSP for coding while HttpSession class is being used for session tracking...
Could anybody tell on how this can be done...
I shall be thankful.
THANKS
ASHU
 
Rehan Malik
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ashu goel:
hi,
What I want to do is that when a person logs in on my site I want to provide him with the date he last logged in..
How can that be done???
I am using JSP for coding while HttpSession class is being used for session tracking...
Could anybody tell on how this can be done...
I shall be thankful.
THANKS
ASHU


You pretty much have two options. You can either add a cookie which holds the last login date/time or you can save that information on YOUR server. I would prefer the cookie method over saving it on your server for obvious reasons.

 
Anoop Krishnan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai Ashu,
You can do it as follows.
If want to manipulate everything in the cache(REMEMBER IF YOU RESTART THE SERVER THE INFORMATION WILL BE LOST) use the javax.servlet.ServletContext or the built in object "application" in jsp for storing your information please go through the following jsp code
<%@ page contentType="text/html" import="java.util.*"%>
<%
String userId=request.getParameter("userid");
HashMap login=(HashMap)application.getAttribute("LOGIN");
if(login==null)
{
application.setAttribute("LOGIN",new HashMap());
login=(HashMap)application.getAttribute("LOGIN");
}
Date lastLogin=(Date)login.get(userId);
if(lastLogin==null)
{
out.println("You are loging first time");
login.put(userId,new Date(System.currentTimeMillis()));
}
else
{
out.println("You logged on "+lastLogin.toGMTString());
login.put(userId,new Date(System.currentTimeMillis()));
}
%>
You could also use the cookies but if the client disables the cookie your attempt will be failed
Create a custom tag library to implement the logic that will be nice & professional
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic