What are the life-cycle methods in JSP?
A JSP page services requests as a servlet. Thus, the life cycle and many of the capabilities of JSP pages (in particular the dynamic aspects) are determined by Java Servlet technology. The life-cycle methods of the JSP are:
-
jspInit(): The container calls thejspInit()to initialize the servlet instance. It is called before any other method, and is called only once for a servlet instance. -
_jspService(): The container calls the_jspService()for each request and it passes the request and the response objects._jspService()method cann?t be overridden. -
jspDestroy(): The container calls this when its instance is about to destroyed.
The jspInit() and jspDestroy() methods can be overridden within a JSP page.
These methods are generated after JSP page translated and compiled, the JSP pages's servlet follows the servlet life-cycle:
- If an instance of the JSP page's servlet does not exist, the container
- Loads the JSP page's servlet class
- Instantiates an instance of the servlet class
- Initializes the servlet instance by calling the
jspInitmethod
- The container invokes the
_jspServicemethod, passing request and response objects.
If the container needs to remove the JSP page's servlet, it calls the jspDestroy method.
Most Recent jsp Faqs
- How to get the real requested URI from inside the error page?
- Can I define a method in a JSP page?
- What is the difference between request.getParameter() and request.getAttribute()?
- What is difference between page and pageContext in JSP pages?
- How to config a JSP file in web.xml?
- What is the difference between jsp:forward and response.sendRedirect?
- How to retrieve values from HTML form input elements in JSP?
Most Viewed jsp Faqs
- What is difference between page and pageContext in JSP pages?
- How to config a JSP file in web.xml?
- How to disable browser caching for a specific JSP?
- How to retrieve values from HTML form input elements in JSP?
- What is the difference between jsp:forward and response.sendRedirect?
- How to get the current JSP page name?
- What is the difference between request.getParameter() and request.getAttribute()?