This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes JSP Page source - Doubt? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JSP Page source - Doubt?" Watch "JSP Page source - Doubt?" New topic
Author

JSP Page source - Doubt?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Guys,

Why can't we override init(ServletConfig) and destroy methods in a jsp page that we write and why is that we can only override jspInit() and jspDestroy()??


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Because the container, who generates the Java code from the JSP, will probably do its own initialization/destruction stuff in those methods. The container deals with methods related ot the lifecycle of the servlet.
If you override them, its important stuff is not going to be called. But the container says "ok, you want to do some initialization yourself too ? I'll give you a chance. Make a jspInit method, and I'll call it. You have my words".


[My Blog]
All roads lead to JavaRanch
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Satou,

I came to know is that the init() and destroy methods are marked final in the HttpJspBase class. This is the reason why we can't override them and instead override the jspInit() and jspDestroy()
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

What is the class that contains init(), destroy() and service() methods for the jsp servlet in other containers. For example in Tomcat, it is HttpJspBase abstract class. Is it the same in all the other containers???
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSP Page source - Doubt?
 
Similar Threads
Regarding _jspService()
All about static methods
override
Service method
Servlet vs JSP