| Author |
jsp translate servlet method problem
|
Harshana Dias
Ranch Hand
Joined: Jun 11, 2007
Posts: 325
|
|
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
Joined: Feb 23, 2009
Posts: 1183
|
|
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.
|
JDBCSupport - An easy to use, light-weight JDBC framework -
|
 |
Harshana Dias
Ranch Hand
Joined: Jun 11, 2007
Posts: 325
|
|
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
Joined: Feb 23, 2009
Posts: 1183
|
|
|
You are free to overwrite but by default the implementation calls the lifecycle methods on it's own...
|
 |
Harshana Dias
Ranch Hand
Joined: Jun 11, 2007
Posts: 325
|
|
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
Joined: Feb 23, 2009
Posts: 1183
|
|
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
Joined: Jun 11, 2007
Posts: 325
|
|
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
Joined: Nov 24, 2005
Posts: 14672
|
|
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 ?
|
[My Blog]
All roads lead to JavaRanch
|
 |
 |
|
|
subject: jsp translate servlet method problem
|
|
|