Daniel Paranhos wrote:
>
>         I want to change a variable stored in jsp application object when
> the user session expires. I'm using the method
> valueUnbound(HttpSessionBindingEvent event) of the
> HttpSessionBindingListener interface to catch this event in one of my java
> classes. I know how to change a variable stored in the session object
> because it comes by parameter in the method valueUnbound.  What should I
> do? Is there anyway to get the application object to a java class?

I suggest that you give the object that listens for the valueUnbound
event a reference to the ServletContext (i.e. the class that's referred
to by the JSP application implicit variable) when it's created, e.g.
something like this:

  package com.mycompany;
  public class SessionHandler implements HttpSessionBindingListener {
      private ServletContext context;

      public void setServletContext(ServletContext context) {
          this.context = context;
      }

      public ServletContext getServletContext() {
          return context;
      }

      public void valueUnbound(HttpSessionBindingEvent event) {
          ServletContext context = getServletContext();
          // Do whatever you want to do with the context variable
      }
      ...
  }

In your JSP page, you can create and initialize it like this:

  <jsp:useBean id="sessionHandler" class="com.mycompany.SessionHandler"
    scope="application">
    <jsp:setProperty name="sessionHandler" property="servletContext"
      value="<%= application %>" />
  </jsp:useBean>

Hans
<plug>
  You find a more detailed example of a bean like this in Chapter 15,
  Developing JavaBeans for JSP, in my JavaServer Pages book.

    <http://TheJSPBook.com/>

</plug>
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com
Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to