You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ralf Mitschke <ra...@jes-software.de> on 2002/06/12 00:41:28 UTC

Listener Objects

Hi!

I would like to know how Listener Objects are instantiated.

And here's my reason :-)
My Class extends HttpServlet and I tried to deal with SessionEvents in the same Class.
So I implemented HttpSessionListener.
But when the sessionCreated/sessionDestroyed methods get the Event any changes made in the Servlet are gone.

For Example: I use a debuging Object of my own, which I instantiate in the Servlet init method. In sessionCreated the Instance is gone and the Reference is null.

My Guess is that I am dealing with 2 different Object instaces.
Are the Listener Objects specified in the web.xml instantiated for themselves?

If so, i could split the Class and encapsulate the session stuff I need to do in another Object.
But could you suggest a method to communicate between my servlet and my sessionListener?

Thanks for your time :-)

Ralf



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Listener Objects

Posted by "Ushakov, Sergey N" <us...@int.com.ru>.
I have just recently merged in the issue...

My results (not necessarily perfect :) are:
- all listener objects are to be declared in web.xml;
- it seems they are instantiated automatically along with the web app;
- it may be a good idea to implement a listener as a special class,
independent of any servlets;
- a good servlet-to-listener communication point is ServletContext;
- to arrange this communication a listener may implement also
ServletContextListener and in its contextInitialized() register itself with
the ServletContext using setAttribute ();
- a servlet can then get reference to the listener via
getServletContext().getAttribute();

The reason of your troubles (if I understood you correct) may be that you
really have two servlet+listener instances. One is instantiated as listener
an so its "init" is never invoked; the other is instantiated as servlet and
does not get listener events.

Regards,
Sergey

----- Original Message -----
From: "Ralf Mitschke" <ra...@jes-software.de>
To: <to...@jakarta.apache.org>
Sent: Wednesday, June 12, 2002 2:41 AM
Subject: Listener Objects


> Hi!
>
> I would like to know how Listener Objects are instantiated.
>
> And here's my reason :-)
> My Class extends HttpServlet and I tried to deal with SessionEvents in the
same Class.
> So I implemented HttpSessionListener.
> But when the sessionCreated/sessionDestroyed methods get the Event any
changes made in the Servlet are gone.
>
> For Example: I use a debuging Object of my own, which I instantiate in the
Servlet init method. In sessionCreated the Instance is gone and the
Reference is null.
>
> My Guess is that I am dealing with 2 different Object instaces.
> Are the Listener Objects specified in the web.xml instantiated for
themselves?
>
> If so, i could split the Class and encapsulate the session stuff I need to
do in another Object.
> But could you suggest a method to communicate between my servlet and my
sessionListener?
>
> Thanks for your time :-)
>
> Ralf
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Listener Objects

Posted by Joe Tomcat <to...@mobile.mp>.
On Tuesday 11 June 2002 12:41, you wrote:
> If so, i could split the Class and encapsulate the session stuff I need to
> do in another Object. But could you suggest a method to communicate between
> my servlet and my sessionListener?

Couldn't you communicate through the ServletContext?  As for instantiating 
Listeners and Servlets, it makes sense that your class was be instantiated 
twice, although someone else would have to give a more definitve answer.  
Maybe you could also use static members in the class so these two instances 
could communicate with eachother?

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>