Home Tutorial Java Servlet HttpSessionBindingEvent example


Share on Google+Share on Google+
HttpSessionBindingEvent example
Posted on: March 24, 2010 at 12:00 AM
In this tutorial you will see how HttpSessionBindingEvent is used in the servlet.


The class HttpSessionBindingEvent exists in the javax.servlet.http package. Its event are sent to an object that implements the HttpSessionListener when it need to bound or unbound a session.


package roseindia.servletexample;

import javax.servlet.http.*;
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.PrintWriter;

public class HttpSessionBindingEventExample extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

PrintWriter out = response.getWriter();

HttpSession session = request.getSession(true);
HttpSessionBindingEvent bind = null;
bind = new HttpSessionBindingEvent(session, "sessionbinding");

if (bind != null) {
out.println("sesion binding sucessfully ");

} else {
out.println("sesion binding failed");



The result is conditional one when the variable bind is holding the name of the object that has been bound to or unbound from a session. If the variable hold some some value it will display "session binding sucessfully" else "sesion binding failed".


Related Tags for HttpSessionBindingEvent example:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 24, 2010

Recommend the tutorial

Advertisements Advertisements