The HttpSessionBindingEvent Class
The HttpSessionBindingEvent class extends HttpSessionEvent. It is generated when a listener
is bound to or unbound from a value in an HttpSession object. It is also generated when an
attribute is bound or unbound. Here are its constructors:
HttpSessionBindingEvent(HttpSession session, String name)
HttpSessionBindingEvent(HttpSession session, String name, Object val)
Here, session is the source of the event, and name is the name associated with the object that is
being bound or unbound. If an attribute is being bound or unbound, its value is passed in val.
The getName( ) method obtains the name that is being bound or unbound. It is shown
String getName( )
The getSession( ) method, shown next, obtains the session to which the listener is being
bound or unbound:
HttpSession getSession( )
The getValue( ) method obtains the value of the attribute that is being bound or unbound.
It is shown here:
Object getValue( )
Handling HTTP Requests and Responses
The HttpServlet class provides specialized methods that handle the various types of HTTP
requests. A servlet developer typically overrides one of these methods. These methods are
doDelete( ), doGet( ), doHead( ), doOptions( ), doPost( ), doPut( ), and doTrace( ). A complete
description of the different types of HTTP requests is beyond the scope of this topic. However,
the GET and POST requests are commonly used when handling form input. Therefore, this
section presents examples of these cases.
Handling HTTP GET Requests
Here we will develop a servlet that handles an HTTP GET request. The servlet is invoked when
a form on a web page is submitted. The example contains two files. A web page is defined
in ColorGet.htm, and a servlet is defined in The HTML source code
for ColorGet.htm is shown in the following listing. It defines a form that contains a select
element and a submit button. Notice that the action parameter of the form tag specifies a URL.
The URL identifies a servlet to process the HTTP GET request.
<form name="Form1"
<select name="color" size="1">
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks