This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes How does a JSP inherit getServletContext() & getServletConfig methods? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "How does a JSP inherit getServletContext() & getServletConfig methods?" Watch "How does a JSP inherit getServletContext() & getServletConfig methods?" New topic
Author

How does a JSP inherit getServletContext() & getServletConfig methods?

Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
1. The JSP is coverted into a Servelet that extends HttpJspBase which is a tomcat implementation of the javax.servlet.http.HttpJspBase interface. This interface extends JspBase, Together these two interfaces have three JSP lifecycle methods, jspInit(), jspService() & jspDestroy(), Then from
how does call to getServletConfig(), getServletContext() in the JSP's lifecycle methods or instance methods work, Where are these methods defined, i know the JSP gets converted to a servlet.
How does a JSP inherit getServletContext() & getServletConfig methods from?


SCJP, SCWCD, SCBCD
Sarat Koduri
Ranch Hand

Joined: Jul 08, 2008
Posts: 83
hi,
i know i am not answering you fully but to make sure you have seen this point...

The servlet generated by the Jsp has an object pageContext which is of type PageContext and this object pageContext has the methods getServletConfig() and getServletContext() ...



:roll:
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
Agreed but Am afraid,you don;t. Cause pageContext is a actually a local variable inside _jspService() and thats how it becomes a implicit object in JSP. The thing is how does jspInit() and jspDestroy() get access to getServletConfig() and getServletContext().
Arun Kumar Gupta
Ranch Hand

Joined: Jul 16, 2008
Posts: 33
hi this is given in Mikalai notes..

The JSP container creates a JSP page implementation class for each JSP page. The name of the JSP page implementation class is implementation dependent. The JSP Page implementation object belongs to an implementation-dependent named package. The package used may vary between one JSP and
another, so minimal assumptions should be made. As of JSP 2.0, it is illegal to refer to any classes from the unnamed (a.k.a. default) package. This may result in a translation error on some containers,

The contract on the JSP page implementation class:
1 Implements HttpJspPage if the protocol is HTTP, or JspPage otherwise.
2 All of the methods in the Servlet interface are declared final.
Additionally, it is the responsibility of the JSP page author that the provided superclass satisfies:
1 The service method of the servlet API invokes the _jspService method.
2 The init(ServletConfig) method stores the configuration, makes it available via getServletConfig, then invokes jspInit.
3 The destroy method invokes jspDestroy.

A JSP container may give a fatal translation error if it detects that the provided superclass does not satisfy these requirements, but most JSP containers will not check them.

Hope it help


SCJP 1.4<br />SCWCD 1.5
Abhijeet Kushe
Greenhorn

Joined: Aug 19, 2008
Posts: 12
The class created by Container for a jsp extends HttpJspBase which is Container Implementation which implements JspPage and HttpJspPage which provide the methods jspInit,jspDestroy,_jspService.

HttpJspBase class extends HttpServlet class and also overrides the service(ServiceRequest,ServiceResponse) and init(ServletConfig) methods to call _jspService and jspInit methods respectively

I think barring the class name rest of the vendors must have the same way for generating .java file for jsp
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How does a JSP inherit getServletContext() & getServletConfig methods?