Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet- inheritance property  RSS feed

 
Josweth Reddy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • 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.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!