Exam Notes
for the Sun Certified Web Component Developer (SCWCD) Exam
3. The Servlet Container Model
3.1. Servlet Context Init Parameters
3.1.1.1. purpose: defines init parameters accessible by
all servlets in the web application context; set-able at
deployment-time, but accessible at run-time
3.1.1.2. interfaces (or classes):
javax.servlet.ServletContext
3.1.1.3. methods: public Enumeration getInitParameterNames()
and public String getInitParameter(String name)
3.1.1.4. webapp deployment descriptor element name:
<context-param> {param-name, param-value}
</context-param>
3.1.1.5. behavior in a distributable: Consider that a
different instance of the ServletContext may exist on each
different JVM and/or machine. Therefore, the context
should not be used to store application state. Any state
should be stored externally, e.g. in a database or ejb.
3.2. Servlet Context Listener
3.2.1.1. purpose: An object that implements the
ServletContextListener interface is notified when its web
app context is created or destroyed
3.2.1.2. interfaces (or classes):
javax.servlet.ServletContextListener
3.2.1.3. methods:
3.2.1.3.1. void contextInitialized(ServletContextEvent e):
called during web server startup or when context is added
or reloaded; requests will not be handled until this
method returns
3.2.1.3.2. void contextDestroyed(ServletContextEvent e):
called during web server shutdown or when context is
removed or reloaded; request handling will be stopped
before this method is called
3.2.1.4. webapp deployment descriptor element name:
<listener> <listener-class> {fully qualified
class name} </listener-class> <listener>
3.2.1.5. behavior in a distributable: Each context
instance (on different jvm's and/or machines) will have
its own instance of the listener object. Therefore, if a
context on one jvm/machine is initialized or destroyed, it
will not trigger a listener on any other jvm/machine.
3.3. Servlet Context Attribute Listener
3.3.1.1. purpose: An object that implements the
ServletContextAttributeListener interface is notified when
attributes are added to or removed from its web app
context
3.3.1.2. interfaces (or classes):
javax.servlet.ServletContextAttributeListener
3.3.1.3. methods: void attributeAdded/attributeRemoved/attributeReplaced(ServletContextAttributeEvent
e)
3.3.1.4. webapp deployment descriptor element name:
<listener> <listener-class> {fully qualified
class name} </listener-class> <listener>
3.3.1.5. behavior in a distributable: Addition, removal or
replacement of an attribute in a context will only affect
the listener for that context, and not other context
"instances" on other jvm's and/or machines.
3.4. HttpSession Attribute Listener
3.4.1.1. purpose: An object that implements the
HttpSessionAttributeListener interface is notified when a
session attribute is added, removed or replaced
3.4.1.2. interfaces (or classes):
javax.servlet.http.HttpSessionAttributeListener
3.4.1.3. methods: void attributeAdded/attributeRemoved/attributeReplaced(HttpSessionBindingEvent
e)
3.4.1.4. webapp deployment descriptor element name:
<listener> <listener-class> {fully qualified
class name} </listener-class> <listener>
3.4.1.5. behavior in a distributable: sessions may migrate
from one jvm or machine to another; hence the session
unbind event may occur on a different jvm/machine than the
session bind event.
3.5. Http Session Listener
3.5.1.1. purpose: An object that implements the
HttpSessionListener interface is notified when a session
is created or destroyed in its web app context
3.5.1.2. interfaces (or classes):
javax.servlet.http.HttpSessionListener
3.5.1.3. methods:
3.5.1.3.1. void sessionCreated(HttpSessionEvent e)
3.5.1.3.2. void sessionDestroyed(HttpSessionEvent e) -
called when session is destroyed (invalidated)
3.5.1.4. webapp deployment descriptor element name:
<listener> <listener-class> {fully qualified
class name} </listener-class> <listener>
3.5.1.5. behavior in a distributable: sessions may migrate
from one jvm or machine to another; hence the session
destroy event may occur on a different jvm/machine than
the session create event.
3.6. Http Session Activation Listener
3.6.1.1. purpose: Designed to handle sessions that
migrate from one server to another. The listener is
notified when any session is about to passivate (move) and
when the session is about to activate (become alive) on
the second host. It gives an app the chance to, for
example, persist nonserializable data across jvm's.
3.6.1.2. mothods:
3.6.1.2.1. void sessionWillPassivate(HttpSessionEvent e) -
session is about to move; it will already be out of
service when this method is called
3.6.1.2.2. void sessionDidActivate(HttpSessionEvent e) -
session has been activated on new server; session will not
yet be in service when this method is called
3.6.1.3. webapp deployment descriptor element name:
<listener> <listener-class> {fully qualified
class name} </listener-class> <listener>
Java
SCJP 6 Exam Download
Java
SCJP 6 Exam Details
Previous
Contents
Next
|