• No results found

iNET Java/JSP/Servlet Course

N/A
N/A
Protected

Academic year: 2022

Share "iNET Java/JSP/Servlet Course"

Copied!
10
0
0

Loading.... (view fulltext now)

Full text

(1)

In this session, you will learn to:

Use Servlet Event Listeners

Objectives

iNET Java/JSP/Servlet Course

(2)

Servlet Event Listeners

A servlet event listener is a Java program that listens for events associated with a servlet.

A listener can be used to monitor and react to events on a servlet life cycle by defining listener objects.

The methods of these listener objects are invoked when life cycle events occur.

To use these listener objects, you must define and specify the listener class.

The servlet container generates events that cause the event listener classes to do something.

iNET Java/JSP/Servlet Course

(3)

Application event listeners are classes that implements one or more of the servlet event listener interfaces.

You can have multiple listener classes listening to each event type and specify the order in which the container invokes the listener beans for each event type.

The various listener interfaces are:

ServletContextAttributeListener HttpSessionListener

ServletRequestListener

ServletRequestAttributeListener HttpSessionBindingListener

HttpSessionAttributeListener ServletContextListener

HttpSessionActivationListener

Types of Event Listeners

iNET Java/JSP/Servlet Course

(4)

You need to perform the following tasks to track the number of concurrent users:

Create a listener class.

Put a <listener> element in the web.xml deployment descriptor.

Create a servlet.

Deploy the servlet

Creating a Event Listener

iNET Java/JSP/Servlet Course

(5)

Challenge

Which of the following listener interfaces will you use if you want to know if an attribute in a web app context has been added, removed, or replaced?

a. ServletContextAttributeListener b. ServletRequestAttributeListener c. HttpSessionListener

d. HttpSessionBindingListener

Answer:

a. ServletContextAttributeListener

iNET Java/JSP/Servlet Course

(6)

Challenge (Contd.)

Which of the following listener interfaces will you use if you want to know about the number of concurrent users?

a. ServletRequestAttributeListener b. HttpSessionListener

c. ServletRequestListener

d. HttpSessionBindingListener

Answer:

b. HttpSessionListener

iNET Java/JSP/Servlet Course

(7)

Challenge (Contd.)

Which of the following listener interfaces will you use if you want to know each time a request comes in, so that you can log it?

a. ServletRequestAttributeListener b. HttpSessionBindingListener

c. ServletRequestListener d. HttpSessionListener

Answer:

c. ServletRequestListener

iNET Java/JSP/Servlet Course

(8)

Challenge (Contd.)

Which of the following listener interfaces will you use if you want to know when a request attribute has been added, removed, or replaced ?

a. ServletRequestAttributeListener b. HttpSessionBindingListener

c. HttpSessionListener d. ServletRequestListener

Answer:

c. ServletRequestAttributeListener

iNET Java/JSP/Servlet Course

(9)

Challenge (Contd.)

Which of the following listener interfaces will you use if you want to know when a session attribute has been added, removed, or replaced?

a. ServletRequestAttributeListener b. HttpSessionBindingListener

c. HttpSessionAttributeListener d. ServletRequestListener

Answer:

c. HttpSessionAttributeListener

iNET Java/JSP/Servlet Course

(10)

In this session, you learned to:

Use Servlet Event Listeners

Summary

iNET Java/JSP/Servlet Course

References

Related documents

Describe how HTML form data is sent in the HTTP request Develop a controller servlet.. Dispatch from a controller servlet to a

Customize a servlet with initialization parameters Explain error reporting within the web form.. Repopulating the

An Analysis model bridges the gap between analysis (of use cases) and design (of application components). Boundary components have two aspects: views and

Design a web application using the Struts MVC framework Develop a Struts action class.. Configure the Struts

In the unpackaged form, each directory and file in the hierarchy exists in the web application directory structure separately.. In the packaged form, the hierarchy is available as

The default session management mechanism uses HTTP cookies. Web containers must also support URL-rewriting for session management when the client has cookies

Request processing by the web container Applying filters to an incoming request Applying filters to a dispatched request Web Container Request Cycle.. iNET

Which of the following methods of the ServletRequestWrapper class is used to return an array of String objects containing all the values of the given request