Share on Google+Share on Google+

HttpSessionBindingEvent example

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;

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".


Posted on: March 24, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.


Advertisement null