• 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

session tracking

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic