• Post Reply Bookmark Topic Watch Topic
  • New Topic

Session log  RSS feed

 
aakash bhatt
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if in my jsp i had initialise a bean of session scope then if i close my browser will the session gets killed and
how do i maintain a log when ever the session gets closed

Thanks,
aakask
 
Dana Hanna
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at:
javax.servlet.http.HttpSessionListener
Per the javadoc:
"Implementations of this interface may are notified of changes to the list of active sessions in a web application. To recieve notification events, the implementation class must be configured in the deployment descriptor for the web application. "
(I'm aware of the bad grammer in the first sentence, but that's what the JavaDoc says - I assume the word "may" should be removed; However, I do question why it was typed in there at all...)
You'll have to create a class, implement this interface, and define all required methods. Your implementation of the method "sessionCreated" would do nothing, and your implementation of "sessionDestroyed" would handle your logging.
I'm not familiar with the use of this interface, just with it's existance. Perhaps someone could clarify how to define it in the web.xml.
What app server are you using?
*Please note that I've taken this from the Java 1.3 documentation. You may be using a different version, and this area of the Java API is being ammended extensivly with every version.
 
nagappan rm
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to use HttpSessionListener

HttpSessionListener is introduced from Java Servlet API v2.3.
And is implemented in Tomcate 4 and higher versions.
A user defined Class ( say MyHttpSessionListener) must implement the HttpSessionListener
sessionCreated(HttpSessionEvent) ---> called whenever a session is created.
sessionDestroyed(HttpSessionEvent se) ---> called whenever a session is destroyed.
U have to registor this class( as given below) in web.xml file which should be in WEB-INF folder.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2.3.dtd">
<web-app>
<!-- Listeners -->
<listener>
<listener-class>
MyHttpSessionListener
</listener-class>
</listener>
</web-app>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!