• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on Jsp methods that are invoked by servlet container

 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()

Answer:B

Source: JavaBeat.com

Can anybody tell as to why the answer is B.
With regards,
Padma priya N.G.
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Priya,

Did you gone thropugh the lifeCycle of JSP ?

Those are first steps learning JSP.

I think you learning from the Questions
instead of reading the book and giving exams.

This is not correct.
 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arnab Sinha
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


Hello Padma,

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.

Arnab
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Priya,

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:

JspPage, HttpJspPage

A look at each

public interface JspPage
extends javax.servlet.Servlet

Methods:

void jspDestroy()

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.


public interface HttpJspPage
extends JspPage

Methods:

void _jspService(
javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

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:

1. init() method calls jspInit()
2. service() method calls _jspService()
3. destroy method calls jspDestroy()


Like this Servletness and Jspness are fulfilled
[ August 16, 2007: Message edited by: Srinivasan thoyyeti ]
 
Prafulla N. Patil
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are not gone fully through HFSJ
that is why you are coming with such type of doubts
be patient, take some time to study book fully

Best Luck
 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Srinivasan,
Thanks. I have started going through HFSJ.
With regards,
Padma priya N.G.
 
Frederic Thierry
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Srinivasan you are totally. Priya just look into the HFSJ book and you will find most answers to your questions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic