When a user requests the JSP for first time the web container tries to convert it to Java file then the Java file is compiled to form class file then it loads the generated servlet class file.Then the container instantiates the servlet and causes the servlets jspInit() method to run then the objects are created which is ready to accept the objects ie the-jspService() method runs.
The JSP is converted to servlet only once in lifecycle abd after that it behaves as servlet throughout life cycle.
The method name is jspInit() (not jsp_Init()), and it should be called by the particular JspPage implementation (extends Servlet) provided by the container. The JspPage implementation should over-ride the servlet's init() to, at least, call the jspInit() method at the very end.
The individual JSPs that get created by the container will extend the JspPage implementation.
As a general idea (and without any examples to look at now), this is what it may look like:
public abstract class MyContainersJspPageImpl implement HttpJspPage, JspPage, Servlet {
...
public static void init(ServletConfig) {
...
jspInit();
}
//default implementation. do nothing maybe? but let JSPs override me
//if they want to do some initialization at startup...
public static void jspInit() {
}
...
public void service(ServletRequest request, ServletResponse response) {
...
//somehow make HttpServletRequest/Response
_jspService(httpRequest, httpResponse);
...
}
public abstract void _jspService(HttpServletRequest request, HttpServletResponse response);
}
public class MyRealJSPMadeFromDotJSPFile extends MyContainersJspPageImpl {
public void jspInit() { // whatever you do in the jspInit
}
public void _jspService(HttpServletRequest request, HttpServletResponse) {
// do stuff to prepare implicit objects and do error handling
...
//do what you do in JSP
...
//clean up
}
...
}