A Java Server Page life cycle is defined as the process started with its creation which later translated to a servlet and afterward servlet lifecycle comes into play. This is how the process goes on until its destruction.
Following steps are involved in JSP life cycle:
- Translation of JSP page to Servlet
- Compilation of JSP page(Compilation of JSP into test.java)
- Classloading (test.java to test.class)
- Instantiation(Object of the generated Servlet is created)
- Initialization(jspInit() method is invoked by the container)
- Request processing(_jspService()is invoked by the container)
- JSP Cleanup (jspDestroy() method is invoked by the container)
We can override jspInit(), jspDestroy() but we can’t override _jspService() method.
Translation of JSP page to Servlet :
This is the first step of JSP life cycle. This translation phase deals with Syntactic correctness of JSP. Here test.jsp file is transllated to test.java.
Compilation of JSP page :
Here the generated java servlet file (test.java) is compiled to a class file (test.class).
Servlet class which has been loaded from JSP source is now loaded into container.
Here instance of the class is generated. The container manages one or more instance by providing response to requests.
jspInit() method is called only once during the life cycle immediately after the generation of Servlet instance from JSP.
Request processing :
_jspService() method is used to serve the raised requests by JSP.It takes request and response object as parameters.This method cannot be overridden.
JSP Cleanup :
In order to remove the JSP from use by the container or to destroy method for servlets jspDestroy()method is used. This method is called once, if you need to perform any cleanup task like closing open files, releasing database connections jspDestroy() can be overridden.
- Life Cycle of a Servlet
- LogRecord setLoggerName() method in Java with Examples
- HashMap computeIfPresent(key, BiFunction) method in Java with Examples
- BlockingQueue remainingCapacity() method in Java with examples
- HashMap replaceAll(BiFunction) method in Java with Examples
- LogRecord setMessage() method in Java with Examples
- LogRecord getLoggerName() method in Java with Examples
- HashMap getOrDefault(key, defaultValue) method in Java with Examples
- LogRecord setLevel() method in Java with Examples
- Extract all integers from the given string in Java
- Shared Preferences in Android with Examples
- Creating an Server-Client Application using the DatagramPacket and DatagramSocket classes
- MessageDigest getProvider() method in Java with Examples
- DigestInputStream.setMessageDigest() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.