Home Tutorial Java Servlet HttpSessionBindingEvent example

 
 

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

Description:

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.

Code:

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");

}
}
}

Output:

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:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.