This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

jsp translate servlet method problem  RSS feed

 
Ranch Hand
Posts: 352
  • 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.
 
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: 352
  • 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: 352
  • 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: 352
  • 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
 
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 ?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!