Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please explain me Service()

 
RR_ami
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet will always extends javax.servlet.http.HttpServlet from which it inhrit implementation of service() that takes HttpServletRequest,HttpServletResponse.
My question is when my servlet is extending GenricServlet at that time which
service() is called?
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

Firstly an admin matter. You will need to change your screen name to a real first name and last name as it is JavaRanch policy.

Now to your question. I'm not really sure what you are asking here?

There's almost no reason to override the service method. service handles standard HTTP requests by dispatching them to the handler methods for each HTTP request type (the doGet and doPost methods. It does so automatiaclly for your servlet you basically don't have to worry about it.

Does that help?
 
Atul Samnerkar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
** Please change your Name to real name.

Servlet will always extends javax.servlet.http.HttpServlet

>> In real world 99% chance is that you will extend from HttpServlet

My question is when my servlet is extending GenricServlet at that time which service() is called?

>> Now the 1% comes in this case and this time service method of GenericServlet interface is called. This interface provides methods which are protocol independent.

Hope this answers your query.

Thanks,
Atul Samnerkar
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"RR_MO", please check your private messages for an important administrative matter.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Atul Samnerkar:
service method of GenericServlet interface is called. This interface provides methods which are protocol independent.


GenericServlet is not an interface. it is an abstract class .

Hope This Helps
 
Atul Samnerkar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for pointing it out...

Regards,
Atul Samnerkar
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As has been said above, servlets will almost always extend HttpServlet, or (rarely) GenericServlet, although there's little reason to do so because HttpServlet does some useful things that you'd otherwise have to implement yourself.

Strictly speaking, though, what makes a servlet a servlet is that it implements the Servlet interface. As long as the class does that, it can be used as a servlet.

http://faq.javaranch.com/java/ServletsFaq#9 talks about when it makes sense to override the service method.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ULF
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic