GeeCON Prague 2014*
The moose likes Servlets and the fly likes doPost() and doGet() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "doPost() and doGet()" Watch "doPost() and doGet()" New topic
Author

doPost() and doGet()

Chris Brat
Ranch Hand

Joined: May 22, 2003
Posts: 108
Hi,
is it 'correct' to define both the doGet() and doPost() methods in a servlet (as in programatically correct) in order to keep the number of servlets loaded to a minimum or would it be better to only implement one per servlet but have more servlets (in an attempt to simplify design?)...
Is this personal preference?
Thanks again.


SCJP 1.2, SCJP 5, SCBCD
Neeraj Singhal
Ranch Hand

Joined: Aug 13, 2000
Posts: 49
Hi Chris
How does defining doGet() and doPost() affect the number of servlets loaded ??
it entirely depends on the requirement...whether u want to define doGet or doPost. BTW...u can define one and call it in another to achieve same functionality in both the methods.
[ September 30, 2003: Message edited by: Neeraj Singhal ]
Chris Brat
Ranch Hand

Joined: May 22, 2003
Posts: 108
I meant that, I might choose to define only one of the methods per servlet thereby needing more classes to do the same functionality as i would need if i had declared both methods.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

"more classes to do the same functionality"
Well, that alone states that it would be a bad design of OOP principles. You want to keep functionality in one location and anyone that needs that functionality can call that one method. It is easier to maintain and enhance.
Sometimes you might want to consider pulling logic out into its own "helper class" that all Servlets can use and call.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Chris Brat
Ranch Hand

Joined: May 22, 2003
Posts: 108
thank u... that was what i was looking for.
 
 
subject: doPost() and doGet()