I'm trying to come up with a workaround for the lack of any method in the SimpleTagSupport API for getting the current Servlet Request. I read a hint on a website that the EL expression evaluation API can be used, and I'm trying to get it to work using a variation of the following approach. Is what I'm trying even possible?
I've solved it! There was a servlet-2.3.jar and a jsp-api-2.0.jar file on my project classpath, and the compiler was loading the PageContext from the servlet jar, which seems to be incompatible with the jsp-api JspContext. Thanks for your help.
But I have one basic doubt. How did this approach work? PageContext is a child of JspContext. And PageContext has extra methods such as getRequest() which are not defined for JspContext. If I cast an object of JspContext into PageContext and access getRequest from this instance, shouldn't I get a run time exception? How can the object of JspContext access a method which it has not defined? Is this some kind of a new trick?
No, this is just basic Java. The instance of the object is an instance of PageContext to begin with, so there's no problem casting it to what it really is.