• 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

Servlet method execution sequence

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I have the following two classes:




Now when I have a POST request coming in from a JSP form where "action" is ServletTwo, is the following sequence of method calls correct?

1. init() of ServletTwo is called which in turns calls init() in ServletOne which in turns calls init() in HttpServlet
2. service() of ServletTwo is called which in turns calls service() in ServletOne which in turns calls service() in HttpServlet
3. doPost() of ServletOne is called.
4. methodOne() is called in ServletTwo ???
 
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A few logging statements will help you track the execution.
 
Ranch Hand
Posts: 686
Mac
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems your assumption is techically correct, but why don't you follow Bear.
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Now when I have a POST request coming in from a JSP form where "action" is ServletTwo, is the following sequence of method calls correct?


No.
[ October 13, 2006: Message edited by: sven studde ]
 
Jignesh Patel
Ranch Hand
Posts: 686
Mac
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I said your assumption is correct as per j2ee specification but almost all server has a different way to handle the request.
 
sven studde
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jignesh Patel:
As I said your assumption is correct as per j2ee specification...


Incorrect. This is wrong per specification of Java 1.5:

init() of ServletTwo is called


[ October 14, 2006: Message edited by: sven studde ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest you follow Bear's advice; if for no other reason that doing so would point out any other issues that your code may have.

The first issue is that ServletTwo is abstract so will not run at all.
You can not instanciate abstract classes.

If you remove the abstract keyword and recompile, then yes, number one is correct.

Number two is also correct (but you do realize that there is no need to override the service method, correct?).

Number three is correct, methodOne will be called.
It will then be called again, and again, until your app blows up with a StackOverflowError.


Sven,
"No" and "Incorrect. This is wrong per specification of Java 1.5" aren't really helpful answers. If there is something that we're missing, maybe you could point out what it is?
 
sven studde
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The first issue is that ServletTwo is abstract so will not run at all.

 
Bring me the box labeled "thinking cap" ... and then read 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