• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

review question chap 9.

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
I would like to check the answer of a question in one of the books i am currently reading:
which of the following methods can be overridden by the author of a jsp page?
1) void jspInit()
2) void _jspService(http.., http..)
3) void jspDestroy()
4) none of the above
The book answers D.
Since _jspService should not be overridden. The first and the third answer fail to define the correct method, (the preceding underscore is missing) so it would not be an override.
My question is, is it true that this is not an override ? Are the real methods indeed _jspInit and _jspDestroy ?
This is because everywhere else in this chapter it is always refered to as the function without underscore. (my book, page 306 under figure 9.3, and page 307 in the explanation of the process)
any ideas, answers are greatly appreciated
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friso,
Answer D (None of the above) is correct.
As you know any jsp page is finally converted into a Servlet which is then compiled, compiled class is instantiated , loaded into memory to service users requests.
There are basically 3 important jsp lifecycle methods. Their exact signature are
1. public void jspInit() { }
2. public void _jspService(HttpServletRequest req, HttpServletResponse res) throws ServletException , IOException { }
3. public void jspDestroy()
Note that only _jspService has the underscore in front of it but not the others. Basically the jsp's converted java class file implements 'HttpJspPage' interface which extends from 'JspPage' , which inturn extends from 'Servlet' interface. So essentially the auto generated java class of the jsp file implements all 3 interfaces.
Generally the jsp vendors provide a vendor specific Base class which implements 'HttpJspPage' interface. It has concrete implemtations for public void jspInit() and public void jspDestroy(), and the 3rd method _jspService(req,res)'s implemented dynamically at the time the jsp page is converted to a java file.
Since _jspService(req, res) is automatically 'added' by the jsp engine, we can't even try to override , because in Java there can't be 2 methods of same signature rigth?
But we CAN override the other 2 lifecycle methods jspInit() and jspDestroy(). But again in Java we can't make the access modifier more restrictive when we override. Meaning we can't override a 'public' access level method with a method of 'package' level. This is the reason why the other answers are incorrect. They do not have the important 'public' access modifier.
Regards,
Maha Anna
 
friso jonge
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks maha,
hmm... still..
So you can override jspInit and jspDestroy as long as you make them public. This is exactly what you do when you add them as a declaration, <%!...%> tag.
You are in my opinion allowed to override above functions (not _jspService()!!)
the question is which function can we override. The answer is then none of the above since none of them exist. (and not the book answer that the preceding underscore is missing in answer 1 and 3)
can someone further elaborate on how to interpret this question ?
thanks,
friso
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I can say is the explanation "The first and the third answer fail to define the correct method, (the preceding underscore is missing)" is incorrect.
 
Bartender
Posts: 3904
43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
LOL !
You guys should look here:
http://www.sybex.com/erratatracking.nsf/WebErrataDocs/B73EE3E4E1D071E988256C16007F1E60?OpenDocument
As stated there
----
The options for Question #1, should read, see detailed description:
A. void _jspInit()
B. void_jspService(HttpServletRequest request,
HttpServletResponse response)
C. void _jspDestroy()
D. None of the above
----
Obvious, question has errors, because an explanation was VERY-VERY strange (for the most of ranchers ) !!!

Originally posted by ks wong:
What I can say is the explanation "The first and the third answer fail to define the correct method, (the preceding underscore is missing)" is incorrect.


 
Everybody! Do the Funky Monkey! Like this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic