Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > newbie question : HttpSessionBindingListener Interface

Reply
Thread Tools

newbie question : HttpSessionBindingListener Interface

 
 
pincopallo_it@yahoo.it
Guest
Posts: n/a
 
      02-06-2006
I got a servlet and and I d like to use the interface
HttpSessionBindingListener to check when session expires and give a
message to the user
I did not find examples about how to use it...
Anyone can help ?
thats what I do:
1) public class GUIControllerRead extends HttpServlet
public class GUIControllerRead extends HttpServlet implements
HttpSessionBindingListener // I add the interface in this way
2)I added this code
HttpSessionBindingEvent firstry= new HttpSessionBindingEvent;

public void valueUnbound(firstry) {
System.out.println ("Expired session " );
}
public void valueBound(firstry) {
System.out.println ("Active session " );
}

protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException
{

int id_eins;

session = request.getSession();
request.setAttribute("guicontroller",
this.getClass().getName());

Enumeration en = request.getParameterNames();
while (en.hasMoreElements()) {
...

Thanks
Gianni

 
Reply With Quote
 
 
 
 
stefanomnn
Guest
Posts: n/a
 
      02-06-2006
Hi, Gianni, it's simple! you make a class like this

package mypack;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;

public class MySessionListener implements
javax.servlet.http.HttpSessionListener,
javax.servlet.http.HttpSessionAttributeListener
{
private String name = null;
private HttpSession session = null;

public void sessionCreated(HttpSessionEvent event)
{
session = event.getSession();
}

public void sessionDestroyed(HttpSessionEvent event)
{
session = event.getSession();
/* handle event */
}

public void attributeAdded(HttpSessionBindingEvent event)
{
name = event.getName();
session = event.getSession();
}

public void attributeRemoved(HttpSessionBindingEvent event)
{
name = event.getName();
session = event.getSession();
}

public void attributeReplaced(HttpSessionBindingEvent event)
{
name = event.getName();
session = event.getSession();
}
}

then, in web.xml, add this (before declaring your servlet):

<listener>
<listener-class>mypack.MySessionListener</listener-class>
</listener>

i hope i helped you!

 
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
Going from higher security level interface to lower security interface- HELP!!! - AM Cisco 4 12-28-2004 09:52 PM
PCI interface or USB interface David Wireless Networking 4 09-16-2004 01:01 PM
allow ssh only on outside interface, but telnet on inside interface of router no-one Cisco 0 07-28-2004 04:17 PM
PIX: how to allow 1 host from outside interface to access another host on the inside interface? jonnah Cisco 1 04-21-2004 02:26 PM
static nat between phisical interface and virtual interface on same ethernet Andrea Cisco 0 04-19-2004 09:37 AM



Advertisments