You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by YMikulski <YM...@infonet.by> on 2001/08/15 22:43:16 UTC

interesting mistake in the tomcat implementation jsp standart.

Hello!
I found a mistake in implementation jsp standart.
Please, look at this code and comments in it.
------------------------------------------------------
package test;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class TestTag extends TagSupport implements
HttpSessionBindingListener, java.io.Serializable {

  public final int doEndTag() throws JspException {
    pageContext.getSession().setAttribute("stat.notify", this);
  }

  public void valueUnbound(HttpSessionBindingEvent event) {
   // MISTAKE!!!
   // When session expires or we execute session.invalidate(),
   // valueUnbound method is called and pageContext.getServletContext()
   // returns null!!! (in this example: context is null).
   ServletContext context = pageContext.getServletContext();
  }
}
--------------------------------------------------------------------
Regards, Yauheni Mikulski




Re: interesting mistake in the tomcat implementation jsp standart.

Posted by "Craig R. McClanahan" <cr...@apache.org>.
This is a user error.

It is not valid to reference pageContext outside the actual execution of
the tag.  Once doEndTag() is called, none of the instance variables have
any valid values.


Craig McClanahan


On Wed, 15 Aug 2001, YMikulski wrote:

> Hello!
> I found a mistake in implementation jsp standart.
> Please, look at this code and comments in it.
> ------------------------------------------------------
> package test;
> 
> import javax.servlet.*;
> import javax.servlet.http.*;
> import javax.servlet.jsp.*;
> import javax.servlet.jsp.tagext.*;
> 
> public class TestTag extends TagSupport implements
> HttpSessionBindingListener, java.io.Serializable {
> 
>   public final int doEndTag() throws JspException {
>     pageContext.getSession().setAttribute("stat.notify", this);
>   }
> 
>   public void valueUnbound(HttpSessionBindingEvent event) {
>    // MISTAKE!!!
>    // When session expires or we execute session.invalidate(),
>    // valueUnbound method is called and pageContext.getServletContext()
>    // returns null!!! (in this example: context is null).
>    ServletContext context = pageContext.getServletContext();
>   }
> }
> --------------------------------------------------------------------
> Regards, Yauheni Mikulski
> 
> 
> 
>