Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > jsp: listener on session close

Reply
Thread Tools

jsp: listener on session close

 
 
AndiArt
Guest
Posts: n/a
 
      06-13-2008
Hi,
I developed a monitoring for my web programm, which shows, which users
are online. For that reason, if I log in or log out, an entry is made
into and deleted from the database. But if the session expires, it
should also delete the corresponding entry from the database.
I used a javax.servlet.http.HttpSessionActivationListener but it
doesn't work. I'd like to show you my source code:

the listener:
----------------------------------
package de.hc.listener;

import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionEvent;

public class SessionPassivateListener implements
HttpSessionActivationListener {

@Override
public void sessionDidActivate(HttpSessionEvent arg0) {

}

@Override
public void sessionWillPassivate(HttpSessionEvent evt) {
de.hc.Password pwd =
(de.hc.Password)evt.getSession().getAttribute("pwd ");
try {
System.out.println("Hello!");
pwd.LogoutProtokoll();
} catch (Exception e) {

}
}

}
---------------------------
my web.xml:
---------------------------

<listener>
<listener-class>
de.hc.listener.SessionPassivateListener
</listener-class>
</listener>

<session-config>
<session-timeout>1</session-timeout>
</session-config>

-----------------------------------
There isn't even the output "hello" on the console, if the session
expires.

Can anyone help me?
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      06-13-2008
On Jun 13, 5:23*pm, AndiArt <(E-Mail Removed)> wrote:
> ...it doesn't work.


Maybe it is just tired. Give it a good nights
rest, and try it in the morning.

>..I'd like to show you my source code:


Good call. Try changing your method like this,
see what the output is..

> * * * * @Override
> * * * * public void sessionWillPassivate(HttpSessionEvent evt) {

..
> * * * * * * * * try {


// moved this code within the try/catch
> de.hc.Password pwd =
> (de.hc.Password)evt.getSession().getAttribute("pwd ");



> * * * * * * * * * * * * System.out.println("Hello!");
> * * * * * * * * * * * * pwd.LogoutProtokoll();
> * * * * * * * * } catch (Exception e) {


// be very noisy
e.printStackTrace();

>
> * * * * * * * * }
> * * * * }
>
> }

...

--
Andrew T.
 
Reply With Quote
 
 
 
 
AndiArt
Guest
Posts: n/a
 
      06-13-2008
Thanks Andrew,

it doesn't print any stack trace. For me it seems, that the listener
is never been called. But I don't know why.

Andreas S.
 
Reply With Quote
 
Owen Jacobson
Guest
Posts: n/a
 
      06-13-2008
On Jun 13, 3:23*am, AndiArt <(E-Mail Removed)> wrote:
> Hi,
> I developed a monitoring for my web programm, which shows, which users
> are online. For that reason, if I log in or log out, an entry is made
> into and deleted from the database. But if the session expires, it
> should also delete the corresponding entry from the database.
> I used a javax.servlet.http.HttpSessionActivationListener but it
> doesn't work. I'd like to show you my source code:
>
> the listener:
> ----------------------------------
> package de.hc.listener;
>
> import javax.servlet.http.HttpSessionActivationListener;
> import javax.servlet.http.HttpSessionEvent;
>
> public class SessionPassivateListener implements
> HttpSessionActivationListener {


...

> }
>
> ---------------------------
> my web.xml:
> ---------------------------
>
> * * * * <listener>
> * * * * * * * * <listener-class>
> * * * * * * * * * * * * de.hc.listener.SessionPassivateListener
> * * * * * * * * </listener-class>
> * * * * </listener>


...

>
> -----------------------------------
> There isn't even the output "hello" on the console, if the session
> expires.
>
> Can anyone help me?


Wrong interface.

The HttpSessionActivationListener and HttpSessionBindingListener
interfaces are intended to be implemented by objects placed in the
session context:

HttpSessionActivationListener foo = new ... ();
request.getSession(true).setAttribute ("foo", foo);

For application-wide session lifecycle listeners, use
HttpSessionListener, from the same package.

-o
 
Reply With Quote
 
AndiArt
Guest
Posts: n/a
 
      06-13-2008
>
> Wrong interface.
>
> The HttpSessionActivationListener and HttpSessionBindingListener
> interfaces are intended to be implemented by objects placed in the
> session context:
>
> * HttpSessionActivationListener foo = new ... ();
> * request.getSession(true).setAttribute ("foo", foo);
>
> For application-wide session lifecycle listeners, use
> HttpSessionListener, from the same package.
>
> -o- Hide quoted text -
>
> - Show quoted text -


Hello, thanks.
Is the programmatically registered HttpSessionActivationListener in
my Session context also called automatically when the session is about
to be closed? I tried it, but no sucess. i need this behaviour,
because I want to do something with a session contexed bean before
really closing the session.
 
Reply With Quote
 
Owen Jacobson
Guest
Posts: n/a
 
      06-13-2008
On Jun 13, 10:40*am, AndiArt <(E-Mail Removed)> wrote:
> > Wrong interface.

>
> > The HttpSessionActivationListener and HttpSessionBindingListener
> > interfaces are intended to be implemented by objects placed in the
> > session context:

>
> > * HttpSessionActivationListener foo = new ... ();
> > * request.getSession(true).setAttribute ("foo", foo);

>
> > For application-wide session lifecycle listeners, use
> > HttpSessionListener, from the same package.

>
> > -o- Hide quoted text -

>
> > - Show quoted text -

>
> Hello, thanks.
> *Is the programmatically registered HttpSessionActivationListener in
> my Session context also called automatically when the session is about
> to be closed? I tried it, but no sucess. i need this behaviour,
> because I want to do something with a session contexed bean before
> really closing the session.


You want HttpSessionBindingListener for that, not Activation. The
term "activation", in the context of J2EE, almost universally means
the phase of an object's lifecycle after it's been deserialized but
before it's made available to the application using it. For session
attributes in an HttpSession, passivation occurs when an attribute is
serialized prior to being migrated to another node in a cluster, and
activation occurs when the attribute is deserialized in its new home.

HttpSessionBindingListener methods are fired when an object is added
to or removed from an HttpSession, which should include when the
session ceases to exist (either due to timeout or invalidation).

The bean you want to "do something with" could implement
HttpSessionBindingListener itself and do something with itself.

-o
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      06-15-2008
AndiArt wrote:
> I developed a monitoring for my web programm, which shows, which users
> are online. For that reason, if I log in or log out, an entry is made
> into and deleted from the database. But if the session expires, it
> should also delete the corresponding entry from the database.
> I used a javax.servlet.http.HttpSessionActivationListener but it
> doesn't work. I'd like to show you my source code:


> public class SessionPassivateListener implements
> HttpSessionActivationListener {
>
> @Override
> public void sessionDidActivate(HttpSessionEvent arg0) {
>
> }
>
> @Override
> public void sessionWillPassivate(HttpSessionEvent evt) {


> <listener>
> <listener-class>
> de.hc.listener.SessionPassivateListener
> </listener-class>
> </listener>
>
> <session-config>
> <session-timeout>1</session-timeout>
> </session-config>


You need to implement HttpSessionListener with sessionCreated
and sessionDestroyed and maintain a HashMap or similar around with
the users.

http://saloon.javaranch.com/cgi-bin/...&f=50&t=005749
http://forum.java.sun.com/thread.jsp...sageID=2609106

shows some code fragments.

Arne
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      06-29-2008
On Jun 13, 5:23=A0pm, AndiArt <(E-Mail Removed)> wrote:
> ...it doesn't work.


Maybe it is just tired. Give it a weak ice ages
rest, and try it in the morning.

>..I'd like to show you my property syntax:


Good call. Try changing your exposure like this,
see what the output is..

> =A0 =A0 =A0 =A0 @Override
> =A0 =A0 =A0 =A0 public void sessionWillPassivate(HttpSessionEvent evt) {

=2E.
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 try {


> de.hc.Password pwd =3D
> (de.hc.Password)evt.getSession().getAttribute("pwd ");



> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 System.out.println("Hello!=

");
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pwd.LogoutProtokoll();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } catch (Exception e) {


e.printStackTrace();

>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 }
>
> }

=2E..

--
Betty T.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[NWO, degenerate, Skull and Bones, propaganda, brainwash, mind control,
fanatic, deranged, idiot, lunatic, retarded, zomby, puppet]

"This is still a dangerous world. It's a world of madmen and
uncertainty and potential mential losses."

--- Adolph Bush,
At a South Carolina oyster roast, as quoted in the
Financial Times, Jan. 14, 2000

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
This is just a reminder.
It is not an emergency yet.
Were it actual emergency, you wouldn't be able to read this.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to close a TCP socket? (TCPSocket#close doesn't close it) I├▒aki Baz Castillo Ruby 7 01-12-2010 01:32 PM
this.Connection.Close(); does not close the Oracle session! Pleasehelp! S_K ASP .Net 6 12-07-2007 02:07 PM
having trouble with event listener: detect iframe close event fromparent Mike Scirocco Javascript 4 04-05-2007 03:19 AM
JavaMail POP3 folder.close() method close also store! Daniel Albisser Java 1 04-07-2004 03:45 PM
How to close child browser while parent close? Denon ASP .Net 1 11-14-2003 08:14 AM



Advertisments