Hi, Select the correct order that JSP methods are invoked by servlet container. Please select one correct answer. A. jspInit(),jspService,jspDestroy() B. jspInit(),_jspService,jspDestroy() C. _jspInit(),jspService,_jspDestroy() D. _jspInit(),_jspService,_jspDestroy()
Can anybody tell as to why the answer is B. With regards, Padma priya N.G.
Padma priya N.G.
Be the change you want to be - Mahatma Gandhi
Hi Srinivasan, According to me, the lifecycle of a jsp consists of init(), service() and destroy() methods. In the question given above, Init(),_Service() and Destroy() methods is chosen as the option. So, I am confused. With regards, Padma priya N.G.
Originally posted by padmapriyagururajan priya: Hi Srinivasan, According to me, the lifecycle of a jsp consists of init(), service() and destroy() methods. In the question given above, Init(),_Service() and Destroy() methods is chosen as the option. So, I am confused. With regards, Padma priya N.G.
If you read the section on lifecycle of a jsp in HFSJ, you will notice the naming conventions. Answer B is correct because it is _jspService. Ans A is incorrect because of incorrect name. Hope this helps.
SCJP 1.4: 91%<br />SCWCD 1.4: 85%
Joined: Feb 15, 2007
I think you might have derived it from people saying
"JSP is Servlet". offcource it is but Go through this:
A JSP has to implement JSP ness and Servlet ness.
For that they came up with two interfaces which can satisfy both the needs:
A look at each
public interface JspPage extends javax.servlet.Servlet
The jspDestroy() method is invoked when the JSP page is about to be destroyed.
void jspInit() The jspInit() method is invoked when the JSP page is initialized.
The _jspService()method corresponds to the body of the JSP page.
So the Jsp implementation(for HTTP) Shall contain implementation for HttpJspPage[(JspPage,Servlet)-->implied)] So it contains implementation for _jspService() jspInit() jspDestroy() and init() service() destroy() and remaining servlet interface methods;
Now Coming to your point JSP is a servlet. yes Now you know the implemention calss has all the above methods implemnted.
How the servlet methods invoking the Jsp mehtods see this: