Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets

 
Gopinath Reddy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference between writing our buisness login codings in Service method block and writing codings in doGet() method and doPost() method.
which one is better to follow.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The basic rule is that you should never write code in the "service" method unless you are radically changing the way HTML behaves. A "service" method is provided for you by the servlet container, which does a lot of clever work deciding whether the request is GET, PUT, HEAD, OPTIONS and so on. You should never need to mess with this in normal servlet application programming.
On the other hand, you don't want to duplicate your code in both the doGet and doPost methods, so what most of us do is something like the following:

This way you ensure that you write your code only once, and it will only be called for ordinary GET and POST requests, and not for any of the other wierd ones.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic