File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Confusion about overriding jsp equivalent init() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Confusion about overriding jsp equivalent init()" Watch "Confusion about overriding jsp equivalent init()" New topic

Confusion about overriding jsp equivalent init()

Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774

Here is a exam watch from david bridge water book and i am unable to understand what it means, please help

If you want to harness jspInit() and jspDestroy() for your own setup and tear-down processes,
you can—by overriding either or both in a JSP declaration, which we explore a little later in this chapter. What if you
decided to override the servlet equivalents, init(ServletConfig config) and destroy()? Well, the JSP spec says
you can’t and mustn’t do this. Most JSP container providers prevent this happening by making all Servlet interface methods
fi nal in the base JSP servlet that they provide—your generated JSP servlet that inherits from this can’t possibly override
them. And while on the subject of overriding, you can’t override _jspService() either. This method represents your page source
in Java code form—it’s up to the clever container’s page generators to worry about the implementation and generation of this
method for each individual JSP. It makes no sense for you to override it within the JSP page itself.

Any points would be helpful.

My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper

Joined: Apr 07, 2010
Posts: 2042

Hi Prithvi,

It just tells you that (if you really want to) you can override the jspInit() and jspDestroy() methods but you can't override the Servlets equivalents (although a JSP is a Servlet). Furthermore remember that your JSP is generated into a Servlet, and this is what the API tells you:

The _jspService()method corresponds to the body of the JSP page. This method is defined automatically by the JSP container and should never be defined by the JSP page author.

I agree. Here's the link:
subject: Confusion about overriding jsp equivalent init()
It's not a secret anymore!