blob: 1462cc6203b52397592fc1022c75fb2746ec4c57 [file] [log] [blame]
kprice96ee3b52008-05-15 00:05:07 +00001<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
kpricead5e1e92008-04-24 00:02:23 +00002<html lang="en-us" xml:lang="en-us">
3<head>
4<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
kprice96ee3b52008-05-15 00:05:07 +00005<meta name="copyright" content="Copyright (c) 2000, 2008 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html. Contributors: IBM Corporation - initial API and implementation" />
6<meta name="DC.rights.owner" content="(C) Copyright 2000, 2008" />
kpricead5e1e92008-04-24 00:02:23 +00007<meta content="public" name="security" />
8<meta content="index,follow" name="Robots" />
kprice96ee3b52008-05-15 00:05:07 +00009<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
kpricead5e1e92008-04-24 00:02:23 +000010<meta content="task" name="DC.Type" />
11<meta name="DC.Title" content="Creating Listeners" />
kprice96ee3b52008-05-15 00:05:07 +000012<meta name="abstract" content="The listener wizard helps you create application lifecycle listeners by walking you through the creation process and by providing you with output files that you can use or that you can modify for use with your Web application. The listeners can run on Java EE-compliant Web servers." />
13<meta name="description" content="The listener wizard helps you create application lifecycle listeners by walking you through the creation process and by providing you with output files that you can use or that you can modify for use with your Web application. The listeners can run on Java EE-compliant Web servers." />
14<meta content="servlets, creating" name="DC.subject" />
15<meta content="servlets, creating" name="keywords" />
16<meta scheme="URI" name="DC.Relation" content="../topics/cwlistbn.html" />
kpricead5e1e92008-04-24 00:02:23 +000017<meta content="XHTML" name="DC.Format" />
18<meta content="twlstwiz" name="DC.Identifier" />
19<meta content="en-us" name="DC.Language" />
kprice96ee3b52008-05-15 00:05:07 +000020<link href="../../org.eclipse.wst.doc.user/common.css" type="text/css" rel="stylesheet" />
kpricead5e1e92008-04-24 00:02:23 +000021<title>Creating Listeners</title>
22</head>
kprice96ee3b52008-05-15 00:05:07 +000023<body id="twlstwiz"><a name="twlstwiz"><!-- --></a>
kpricead5e1e92008-04-24 00:02:23 +000024
25
26<h1 class="topictitle1">Creating Listeners</h1>
27
kpricead5e1e92008-04-24 00:02:23 +000028
kprice96ee3b52008-05-15 00:05:07 +000029
30<div><p>The listener wizard helps you create application lifecycle listeners by walking you through the creation process and by providing you with output files that you can use or that you can modify for use with your Web application. The listeners can run on Java EE-compliant Web servers.</p>
31
32<div class="section"> <p>To create a listener, complete the following steps: </p>
kpricead5e1e92008-04-24 00:02:23 +000033</div>
34
35<ol>
kprice96ee3b52008-05-15 00:05:07 +000036<li class="stepexpand"><span>From the Java EE perspective, expand your <a href="ccwebprj.html" title="">dynamic project</a> in the Project Explorer view.</span></li>
kpricead5e1e92008-04-24 00:02:23 +000037
kprice96ee3b52008-05-15 00:05:07 +000038<li class="stepexpand"><span>Right click on the <strong>Listener</strong> icon, and select <span class="menucascade"><span class="uicontrol">New</span> &gt; <span class="uicontrol">Listener</span></span> from the pop-up menu.</span> The <span class="uicontrol">Create Listener</span> wizard appears.</li>
kpricead5e1e92008-04-24 00:02:23 +000039
kprice96ee3b52008-05-15 00:05:07 +000040<li class="stepexpand"><span>Follow the project wizard prompts.</span></li>
kpricead5e1e92008-04-24 00:02:23 +000041
42</ol>
43
kprice96ee3b52008-05-15 00:05:07 +000044<div class="section"><dl>
45<dt class="dlterm">Application lifecycle listeners</dt>
kpricead5e1e92008-04-24 00:02:23 +000046
kprice96ee3b52008-05-15 00:05:07 +000047<dd>The <cite>Sun Microsystems Java™ Servlet 2.3 Specification</cite>defines the following interfaces that represent that application lifecycle listeners. You should select at least one of the intefaces. <ul>
48<li><strong>javax.servlet.ServletContextListener:</strong> This interface is provided by javax.servlet package and can be used to listen to the ServletContext life-cycle events. This interface has two methods: contextInitialized and contextDestroyed. The <strong><em>contextInitialized</em></strong> method is called when the web application is ready to service requests and the <strong><em>contextDestroyed</em></strong> method is invoked when the servlet context is about to be shut down.</li>
kpricead5e1e92008-04-24 00:02:23 +000049
kprice96ee3b52008-05-15 00:05:07 +000050<li><strong>javax.servlet.ServletContextAttributeListener:</strong> This interface is provided by javax.servlet package. It can be used to be notified when any attribute is added to the ServletContext or if any of the ServletContext's attributes are changed or removed. This inetface has three methods: <strong><em>attributeAdded, attributeRemoved</em></strong> and <strong><em>attributeReplaced</em></strong>.</li>
kpricead5e1e92008-04-24 00:02:23 +000051
kprice96ee3b52008-05-15 00:05:07 +000052<li><strong>javax.servlet.ServletRequestListener:</strong> This interface is provided by javax.servlet package. It can be used to be notified when a request is coming in or out of scope in a Web component. This interface has two methods: requestInitialized and requestDestroyed. The <strong><em>requestInitialized</em></strong> method is called when it is about to enter the first servlet or filter in each Web application. The <strong><em>requestDestroyed</em></strong> method is called when it exits the last servlet or the first filter in the chain.</li>
kpricead5e1e92008-04-24 00:02:23 +000053
kprice96ee3b52008-05-15 00:05:07 +000054<li><strong>javax.servlet.ServletRequestAttributeListener:</strong> This interface is provided by javax.servlet package and can be used to be notified when any request attribute is changed. This interface has three methods: attributeAdded, attributeRemoved and attributeReplaced. The <strong><em>attributteAdded</em></strong> method is called when a new attribute was added to servlet request. The <strong><em>attributeRemoved</em></strong> method is called when an existing attribute has been removed from the servlet request. The <strong><em>attributeReplaced</em></strong> method is called when an attribute was replaced on the servlet request.</li>
kpricead5e1e92008-04-24 00:02:23 +000055
kprice96ee3b52008-05-15 00:05:07 +000056<li><strong>javax.servlet.http.HttpSessionListener:</strong> This interface is provided by javax.servlet.http package and can be used to listen to a sessions life cycle events. This interface has two methods: sessionCreated and sessionDestroyed. The <strong><em>sessionCreated</em></strong> method is called when an HttpSession object is created. The <strong><em>sessionDestroyed</em></strong> method is called when an HttpSession object is invalidated.</li>
kpricead5e1e92008-04-24 00:02:23 +000057
kprice96ee3b52008-05-15 00:05:07 +000058<li><strong>javax.servlet.http.HttpSessionActivationListener:</strong> This interface is provided by javax.servlet.http package. It can be used to listen to a container events notifying that sessions will be passivated or activated. This interface has two methods: sessionDidActivate and sessionWillPasivate. The <strong><em>sessionDidActivate</em></strong> is called when the session has just been activated and the <strong><em>sessionWillPasivate</em></strong> is called when the session is about to be passivated.</li>
kpricead5e1e92008-04-24 00:02:23 +000059
kprice96ee3b52008-05-15 00:05:07 +000060<li><strong>javax.servlet.http.HttpSessionAttributeListener:</strong> This interface is provided by javax.servlet.http package and can be used to listen to events related to session attributes. This interface has three methods: attributeAdded, attributeRemoved and attributeReplaced. The <strong><em>attributeAdded</em></strong> method is called when an attribute is added to an HttpSession object. The <strong><em>attributeRemoved</em></strong> and <strong><em>attributeReplaced</em></strong> methods are called when an HttpSession attribute is removed or replaced, respectively.</li>
kpricead5e1e92008-04-24 00:02:23 +000061
kprice96ee3b52008-05-15 00:05:07 +000062<li><strong>javax.servlet.http.HttpSessionBindingListener:</strong> This interface is provided by javax.servlet.http package and can be used to be notified when an object is bound to or unbound from a session. This interface has two methods: valueBound and valueUnbound. The <strong><em>valueBound</em></strong> method is called when the object is being bound to a session and identifies the session. The <strong><em>valueUnbound</em></strong> method is called when the object is being unbound from a session and identifies the session.</li>
63
64</ul>
65 </dd>
66
67
68<dt class="dlterm">Modifiers</dt>
69
70<dd>The <cite>Sun Microsystems Java Servlet 2.3 Specification</cite> states that a Listener class must be <strong>public</strong> and not <strong>abstract</strong>. Therefore, you cannot change these modifiers. The only one available for change is the <strong>final</strong> modifier.</dd>
71
72
73<dt class="dlterm">Interfaces</dt>
74
75<dd>The interfaces that you selected in the previous page of the wizard are provided as default values in the <strong>Interfaces</strong> field. To add additional interfaces, click the <strong>Add</strong> button next to this field.</dd>
76
77
78<dt class="dlterm">Interface selection dialog</dt>
79
80<dd>This dialog appears if you select to add an interface to your servlet. As you type the name of the interface that you are adding, a list of available interfaces listed in the <strong>Matching items</strong> list box updates dynamically to display only the interfaces that match the pattern. Choose an interface to see the qualifier, and then click <strong>OK</strong> when finished.</dd>
kpricead5e1e92008-04-24 00:02:23 +000081
82</dl>
83</div>
84
85</div>
kprice96ee3b52008-05-15 00:05:07 +000086
87<div><div class="relconcepts"><strong>Related concepts</strong><br />
88<div><a href="../topics/cwlistbn.html">Listeners</a></div>
89</div>
90</div>
91
kpricead5e1e92008-04-24 00:02:23 +000092</body>
kprice96ee3b52008-05-15 00:05:07 +000093</html>