• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp translate servlet method problem

 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

If the JSP is not invoke by a Servlet then those jspInit(), _jspService(), jspDestroy() are called by the container right?

But if the jsp is invoked via a servlet (like RequestDispating) then do those jspInit(), _jspService(), jspDestroy() methods called by that servlet init(), service(),destroy() is it ?

that is what i understand in the HFSJ 1.5 page 305.

Thank You.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether or not you use a RequestDispatcher to forward to a JSP, or access it directly in the browser, does not matter.

Upon instantiation the container takes care of the lifecycle methods, in either case.
 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sebastian Janisch wrote:Whether or not you use a RequestDispatcher to forward to a JSP, or access it directly in the browser, does not matter.

Upon instantiation the container takes care of the lifecycle methods, in either case.


then why its explain as->

jspInit()

This method is called from the init() method. You can override this method

jspDestroy()

This method is called from the servlets destroy() method. you can overide this too.

_jspService()

This method is called from servlet service method. you cant override this.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are free to overwrite but by default the implementation calls the lifecycle methods on it's own...
 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sebastian Janisch wrote:You are free to overwrite but by default the implementation calls the lifecycle methods on it's own...


ok about override but can you explain this please,

jspDestroy()

This method is called from the servlets destroy() method
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the API http://tomcat.apache.org/tomcat-4.1-doc/jasper/docs/api/org/apache/jasper/runtime/HttpJspBase.html

A JSP page is translated to a plain old servlet. Not quite, the implementation is HttpJSPBase which extends HttpServlet. The final destroy and init method inherited from HttpServlet make the call to _jspInit() etc.

Also, be careful with override and overload. There is a significant difference between the both.
 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now makes sense Sebastian..thank you so much.

One more question please...

it said that the generated servlet implements HttpJspPage interface. but i can see in tomcat is it implements JspSourceDependent interface. may be the interface implementation differ from the vender container right?

Also i guess we are talking here good old friend method overriding right?

Thankx in advanced
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it said that the generated servlet implements HttpJspPage interface. but i can see in tomcat is it implements JspSourceDependent interface. may be the interface implementation differ from the vender container right?

You can also see that it extends HttpJspBase. Guess which interface does HttpJspBase implement ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic