In a JSP, I see the code:
<%= this.getServletContext() %>
(why the unknown party didn't use the application variable, I do not know).
My development environment suggests that the method getServletContext() is not valid within a JSP page. It seems to suggest that a JSP is solely an implementation of the javax.servlet.jsp.HttpJspPage, which doesn't have such a method.
While the JSP Specification seems to make it clear that a translated JSP page implements the javax.servlet.jsp.HttpJspPage interface, it doesn't make it clear if it implements any other interfaces, such as javax.servlet.http.HttpServlet (and thus explaining the code written by the unknown party).
I am requesting suggestions and possible explanations regarding the code written by the unknown party, since my development environment and myself (unless I have overlooked something) both agree that this code is not written according to the specification.
All speculative or concrete answers are most appreciated.
I agree with the fact that we should not use 'this' in JSP and use application etc variables to access the servlet context etc as otherwise our code becomes dependent upon some JSP engines where it works fine and doesn't work on little different environment. I wonder if the third party in the question have made sure that the code provided works within their environment because as you suggested getServletContext() shouldn't be found if it really follows what JSP specification says.
I have observed that different JSP engines generates different Java code for the JSPs. In iPlanet and Tomcat or even different iPlanet versions there are differences b/w the way java files for JSPs are generated.
Once I get to office tomorrow I would check with my iPlanet to see what does it do for JSPs to see if they extend HttpServlet somehow or what...
But in anycase a JSP code should not be dependent upon specific JSP engines..
A JSP page defines a JSP page implementation class that implements the semantics of the JSP page. This class implements the javax.servlet.Servlet interface.
Since getServletContext is defined by GenericServlet (and not the Servlet interface), it's not spec-compliant to rely upon it (even though HttpServlet is always derived from GenericServlet).
That said, I agree that using getServletContext rather than the more conventional 'application' variable is a bad idea (even if it works); if for no other reason than that it's confusing.
[Edited for clarity]
[ February 23, 2004: Message edited by: Bear Bibeault ]
That said, I agree that using getServletContext rather than the more conventional 'application' variable is a bad idea; if for no other reason than that it's confusing.
Even so, that doesn't justify the use of getServletContext() since this interface does not define that method.
Unless I am advised otherwise, I am going to conclude that the code is broken, and dependant upon the container in which it was developed (Disclaimer: I didn't write it !)
Thanks for the suggestions.