JspContext does not provide access to ServletContext because Simple tag support is not bound to servlets. If you want to write a tag that needs some dependency on servlets I suggest to use classic tags.
There may be a question on this concept in the exam
I just wanted to add something tho what has been said so far.
Here's what the spec says in section JSP.7.1.5 about simple tags:
In addition to being simpler to work with, Simple Tag Extensions do not directly rely on any servlet APIs, which allows for potential future integration with other technologies. This is facilitated by the JspContext class, which PageContext now extends. JspContext provides generic services such as storing the JspWriter and keeping track of scoped attributes, whereas PageContext has functionality specific to serving JSPs in the context of servlets. Whereas the Tag interface relies on PageContext, SimpleTag only relies on JspContext.
However, when taking a look into SimpleTagSupport's API pages, this is what they say about the setJspContext method:
public void setJspContext(JspContext pc) Stores the provided JSP context in the private jspContext field. Subclasses can access the JspContext via getJspContext(). Parameters: pc - the page context for this invocation
I tried to output the result of getJspContext() instanceof PageContext inside a class extending SimpleTagSupport, and the result was that the Object returned was in fact a PageContext instance.
In my opinion, what the spec says in section JSP.7.1.5 is the same as with filters' doFilter method receiving ServletRequest and ServletResponse as parameters (instead of HttpServletRequest and HttpServletResponse): it was defined that way to allow future use of SimpleTag (or Filter) outside the context of a web application, but in the context of a web application I think we may assume it is safe to cast getJspContext()'s result into PageContext, as it is safe to cast the ServletRequest and ServletResponse (received in doFilter) to a HttpServletRequest and HttpServletResponse.
Any ideas? Am I going to far in my assumptions? [ April 24, 2007: Message edited by: Sergio Tridente ]
in the context of a web application I think we may assume it is safe to cast getJspContext()'s result into PageContext, as it is safe to cast the ServletRequest and ServletResponse (received in doFilter) to a HttpServletRequest and HttpServletResponse
Being safe is different from being appropriate (good coding practice). If you happen to be using some non-servlet dependent framework/API in future your code may require lot of changes.