ketan patel
Posts: 1
Nickname: k2patel
Registered: Jul, 2004
my session is not get invalidate even after executing it in many way
Posted: Oct 27, 2004 8:10 AM
Advertisement
hi every body i have problem here and what it is i don't know so please some body help me to find out what went wrong 1. when i create a session the sessionList.java will get execute and it working 2. and when i will call the session.invalidate() it will not going to work or the session destroyed event is not going to execute 3. and when i close the window directly the session not going to destroy after the specified time as specified in the web.xml and login.jsp the code is as belowweb.xml <web-app> <listener> <listener-class>com.samagam.sessionList</listener-class> </listener> <session-config> <session-timeout>30</session-timeout> </session-config> <taglib> <taglib-uri>http://jakarta.apache.org/taglibs/mailer-1.1</taglib-uri> <taglib-location>/WEB-INF/taglibs-mailer.tld</taglib-location> </taglib> </web-app> login.jsp logged = sessionList.fnd(id); y = "yes"; if(y.equals(logged)){ if (session.isNew() == false) { session.invalidate(); session = request.getSession(true); } session.setAttribute("userid",id); session.setAttribute("j",l); session.setMaxInactiveInterval(300); } sessionList.java [code]
package com.samagam;
import java.util.HashMap;
import java.util.Hashtable;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
public class sessionList implements javax.servlet.http.HttpSessionListener, javax.servlet.http.HttpSessionAttributeListener
{
private String name = null ;
private HttpSession session = null ;
private String val = null ;
public static Hashtable tb = new Hashtable();
public void sessionCreated(HttpSessionEvent event)
{
session = event.getSession();
tb.put(session,"0" );
}
public void sessionDestroyed(HttpSessionEvent event)
{
session = event.getSession();
tb.remove(session);
}
public void attributeAdded(HttpSessionBindingEvent event)
{
name = (String)event.getName();
session = event.getSession();
val = (String)event.getValue();
if (name.equals("userid" )){
tb.put(session,val);
}
}
public void attributeRemoved(HttpSessionBindingEvent event)
{
name = event.getName();
session = event.getSession();
}
public void attributeReplaced(HttpSessionBindingEvent event)
{
name = event.getName();
session = event.getSession();
}
public static String fnd(String id){
boolean i;
String p;
i = tb.containsValue(id);
//System.out.println(i);
if (i){
p = "yes" ;
return p;
} else {
p="no" ;
return p;
}
}
}
[/code]