File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets" Watch "Servlets" New topic


Gopinath Reddy

Joined: Feb 26, 2004
Posts: 15
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

Joined: Jan 07, 1999
Posts: 6920
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.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: Servlets
It's not a secret anymore!