wood burning stoves 2.0*
The moose likes Servlets and the fly likes HttpSessionListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpSessionListener" Watch "HttpSessionListener" New topic
Author

HttpSessionListener

Chandra Sekhar
Ranch Hand

Joined: Sep 26, 2003
Posts: 90
Hi,

Can someone help me in understanding the usage of HttpSessionListener Interface.

Thanks in Advance
Chandrasekhar S.


"Luck is when opportunity meets preparation"
Atul Prabhu
Ranch Hand

Joined: Dec 17, 2002
Posts: 60
package servlets;
import javax.servlet.*;
import javax.servlet.http.*;

public class SessionServlet extends HttpServlet implements HttpSessionListener
{

public void doGet(HttpServletRequest request,HttpServletResponse response)
{
try{
HttpSession session = request.getSession();
}
catch(Exception e){
System.out.println("Exception: " + e);
}
}

public void sessionCreated(HttpSessionEvent se)
{
System.out.println("Session Created ");
}

public void sessionDestroyed(HttpSessionEvent se)
{
System.out.println("Session Destroyed ");

}


}

If u see above SessionServlet has implemented HttpSessionListener. So when a session is created , method sessionCreated() is called. Similarly sessionDestroyed is called when session is destroyed by the container.

--
Atul
[ September 16, 2004: Message edited by: Atul Prabhu ]
James Clinton
Ranch Hand

Joined: Jun 23, 2003
Posts: 190
Useful for clearing up database connections. HttpSessionListner and others (Context) are clearly explained in the following book:

SCWCD Exam Study Kit, Java Web Component Developer Certifcation
Deshmukh and Malavia

HTH
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpSessionListener
 
Similar Threads
Regarding Servlets
Execute code when a session expires
About Sessions
Get Total session count
handling session time out