Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSessionListener

 
Chandra Sekhar
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

Thanks in Advance
Chandrasekhar S.
 
Atul Prabhu
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic