HttpSessionListener - sounds familiar?
mack81 Mar 28, 2002 6:25 AMHi there folks.I was wondering if any of you used a HttpSessionListener.I'm doing this do automatically set a session attribute (which is a reference to a session bean),each time a new session is initialized. Here is the code:
package listeners;
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSession;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import DBase;
import DBaseHome;
class SessionListener implements HttpSessionListener{
private HttpSession session=null;
private static int nr=0;
public void sessionCreated(HttpSessionEvent se){
session=se.getSession();
DBaseHome objshome=null;
DBase bean=null;
nr++;
System.out.println("The Session listener is in action...Call number "+nr);
try{
InitialContext ic=new InitialContext();
Object ref=ic.lookup("java:comp/env/ejb/DBase");
objshome=(DBaseHome) PortableRemoteObject.narrow(ref,DBaseHome.class);
bean=objshome.create();
}catch (Exception e){
System.out.println("Failed to lookup java:comp/env/ejb/DBase or create the bean");
}
System.out.println("Setting session attribute bean DBase...Call number "+nr);
session.setAttribute("dbase",bean);
}
public void sessionDestroyed(HttpSessionEvent se){
session=se.getSession();
DBase bean=null;
bean=(DBase)session.getAttribute("dbase");
try{
bean.remove();
session.removeAttribute("dbase");
}catch (Exception e){
System.out.println("Failed to remove the bean or remove it as attribute.Call number "+nr);
}
nr--;
}
}
The class compiles just fine.
In web.xml I added the line:
<listener-class>listeners.SessionListener</listener-class>
But unfortunately jboss says:
[13:06:09,103,EmbeddedCatalinaServiceSX] StandardContext[/hosp]: Error configuring application listener of class listeners.SessionListener
java.lang.IllegalAccessException: listeners.SessionListener
at java.lang.Class.newInstance0(Native Method)
Can anyone give me a hint about what is going on here?I am kind of confused...