Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why we use doGet() and doPost() in the place of service(ServletRequest req,servletResponse)

 
Ritesh raushan
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why we use doGet() and doPost() in the place of public void service(ServletRequest req,servletResponse resp).

we can also use service(ServletRequest req,servletResponse resp).
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you want to? It's much easier to use the provided methods.

The service() method is defined in GenericServlet, which was intended to be able to support different protocols. In practice you're always going to be using HTTP. The service() method is implemented in HttpServlet in a way that makes life simpler - it does all the mapping of HTTP requests for you, so all you need to do is implement the ones you want to use.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we have an entry about it in ServletsFaq
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although most people make POST and GET do the same thing, that's a really bad practice. POST and GET should be used for very different things according to the way HTTP was designed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic