I'm a bit puzzled by what looks like a contradiction in the official Sun Certified Web Component Developer guide. It states ( and so does everywhere else I can find on the internet) that in a servlet you can over-ride the Servlet's init method. In the JSP chapter it states that you should over-ride the JspInit method for initilisation stuff. It goes further and says that most containers will prevent you from over-riding the Servlet's init method in a JSP.
My question is this... A JSP is a servlet, you are allowed to over-ride init() for a normal servlet so why not for a JSP?
This is just intellectual curiosity - I wouldn't want to do this (probably) and I'm sure this isn't important for the SCWCD exam.
Thanks in advance for any help, Matt
Joined: Mar 22, 2005
A JSP is a servlet
That's an implementation detail that you should not rely on. The spec says that in a JSP there will be a jspInit method, but I don't think it says that there will be an init method. That's because the JSP spec doesn't mandate that JSPs are implemented by servlets. Every single JSP container in existence may do it that way, but a container is free to do it some other way, in which case there wouldn't be an init method to override.