Forums Register Login

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

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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:
+Pie Number of slices to send: Send
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().
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
Nothing? Or something? Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 9080 times.
Similar Threads
jspInit()
why HttpJspPage extends both JspPage and Servlet interfaces?
getServletConfig() and getServletContext()
servletcontext
servletContext
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:45:38.