• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Clear unused Session Attributes  RSS feed

 
Karthikeyan Ramaswamy
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i'm working on j2ee web application,
regarding unsed sessions we are getting lots of problem,
how to handle such kind problems in future.
suggestions & guidance are welcome.

Thanking you
Karthikeyan R
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What sort of problem?
 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And how is it that you intend to differentiate between used and unused attributes? If it is like, they're set before displaying a particular screen, then you can take care that after the screen has been displayed, you remove the attributes.
You can't arbitrarily decide at a particular point of a user's browsing session which all attributes are used/unused. Unless ofcourse you have a hardcoded list of attributes which define, before every servlet/JSP renders the response, all the possible attribute names that can exist, and remove all other attributes present.
[ May 01, 2008: Message edited by: Anirvan Majumdar ]
 
Bk Jacky
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
State your problem clearly.
 
Karthikeyan Ramaswamy
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i tried this code it's working fine.

try
{
HttpSession session=request.getSession(false);
if(session!=null)
{
Enumeration attributeNames=session.getAttributeNames();
while(attributeNames.hasMoreElements())
{
String sAttribute=attributeNames.nextElement().toString();
if (!sAttribute.equals("org.apache.struts.action.LOCALE")
&& !sAttribute.equals("loginType")
&& !sAttribute.equals("LoginDetails")
&& !sAttribute.equals("SystemConfig")
&& !sAttribute.equals("RoleMenu")
&& !sAttribute.equals("reportContexPath")
&& !sAttribute.equals(GlobalNames.LOGIN_USER_SESSION_ID)
&& !sAttribute.equals("ecsClientId")
&& !sAttribute.equals("explorerClientId"))
{
//System.out.println(request.getRequestURL()+" Removing Session Attribute : "+sAttribute);
session.removeAttribute(sAttribute);
}
}
}
}catch(Exception e) { }
[ May 12, 2008: Message edited by: Karthikeyan Ramaswamy ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!