• 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- inheritance property

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please clarify my doubt in servlets, go through the below statements.

Here is the process what I know in servlets,

1.The browser sends a request to the servlet which is called MyServlet extends HttpServlet

2.The server generates request and response objects and sends these objects to the service() method of MyServlet,which contains doPost() but not service().

3.So the requet sends to the service() method of HttpServlet(Super class of MyServlet)

4.Then the service() method internally calls the doGet or doPost() of MyServlet.


Here is my doubt

--->> How the service() method of HttpServlet(Super class) invokes doGet or doPost() of MyServlet(Subclass)???. I think it voilates the inheritance property.

Thanks in advance.
Josweth Reddy
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


3.So the requet sends to the service() method of HttpServlet(Super class of MyServlet)



request is not being send to service() method of HttpServlet class, it is being send to service() method of your class (that is MyServlet)... this class has got this service() method from HttpServlet class.


--->> How the service() method of HttpServlet(Super class) invokes doGet or doPost() of MyServlet(Subclass)???. I think it voilates the inheritance property.



Hope it is clear.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please refer to some good tutorials regarding "How servlet works". Some are below.

http://java.sun.com/products/servlet/articles/tutorial/
http://www.onjava.com/pub/a/onjava/2003/05/14/java_webserver.html
 
Josweth Reddy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rathi ji:


Hope it is clear.



What will be the case if I used a doPost() in "MyServlet" but not the service() method?.

Thank you
Josweth Reddy
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Josweth Reddy:
What will be the case if I used a doPost() in "MyServlet" but not the service() method?.



What will happen, if you dont override any of your parent's method?
 
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

Originally posted by Josweth Reddy:

3.So the requet sends to the service() method of HttpServlet(Super class of MyServlet)



It doesn't 'send' it to another class's method.
It will call the service method of YOUR servlet.
Your servlet will inherit the service method from HttpServlet.
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic