If JSP turns into a Servlet why there are different life cycle methods for example jspInit() and init() ?
If JSP turns into a Servlet why there are different life cycle methods for
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’ll try to explain it correctly in the most simple way (as addition to the correct @Nathan Hughes answer) :
From the perspective of HTML vs JAVA code, servlet is more like HTML wrapped with JAVA. It gives a strong support for handling application layer in the multilayered architecture. On the other hand JSPs were created to support the creating of presentation layer. The
init()method of a servlet is called only once during initialization of the servlet.So the first point : Servlets were here before JSPs.
Now to JSPs. Again from the perspective of HTML and JAVA, JSP is more like JAVA wrapped with HTML.
WEB CONTAINER performs a translation of the JSP “source code” to the equivalent Servlet java code. This translated java Servlet source code is then compiled and the WEB CONTAINER handles the realisation of the Servlet. Simply:
MyPage.jsp –> (translate) –> MyPage_jsp.java –> (compile) –> MyPage_jsp.class –> (load) –> Java Servlet
The
jspInit()method is called by WEB CONTAINER as a part of the initialization phase of the JSP lifecycle.So to your question :
jspInit()not equalsinit().