Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sarat Koduri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Abhijeet Kushe
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic