This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JSP and the fly likes Over-riding JspInit() butnot Servlets init() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Over-riding JspInit() butnot Servlets init() method" Watch "Over-riding JspInit() butnot Servlets init() method" New topic
Author

Over-riding JspInit() butnot Servlets init() method

Mat Austin
Greenhorn

Joined: Dec 01, 2006
Posts: 7
Hi All,

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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39576
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Over-riding JspInit() butnot Servlets init() method
 
Similar Threads
Questions about ServletContext and ServletConfig
JSP Life Cycle
interview questions - J2EE
jspInit()
Accessing the Servlet Init parameters in jsp