File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes doPost() processes - doGet() displays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "doPost() processes - doGet() displays" Watch "doPost() processes - doGet() displays" New topic

doPost() processes - doGet() displays

Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

I'm trying to go for my SCWCD and am just starting to learn servlets. In most of the books I'm reading and most of the examples I've seen, static HTML pages with forms call the doPost() method of the servlet. When I'm writing the code I make the doGet() method generate the form that calls the doPost() method of the same servlet.

I'm wondering what reason there is not to have the doGet() generate the form that calls the doPost(), since I haven't seen it in any examples...


Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17423

Odd. I have. Maybe it just got less popular after JSPs and MVC-patterned app structures took over.

An IDE is no substitute for an Intelligent Developer.
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

I would think its more a question of design...
I usually like to have a servlet perform one action -- say handle a particular form. And another page (maybe a JSP or HTML) create the form. -- Plus writing out tons of HTML code in a servlet is a pain... all those out.println("..."); statements... whereas in a JSP you can simply write the HTML.
The other point in the argument is from a mainteance stand point... it might be harder to maintain if you have one giant servlet that creates the form and handles the input, rather than two pieces that handle the same thing...
Just some thoughts...

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Amir Kamran
Ranch Hand

Joined: Apr 21, 2002
Posts: 48
when we use simple form of html and want some dynamic behaviour in reply of the form, it is easy to use simple html file to display form and a servlet which handles it. But it is not a rule.
I think, it is good to generate the forms from within a servlet b/c it increase the functionality of the form as we can make the forms dynamic too.
I agree. Here's the link:
subject: doPost() processes - doGet() displays
It's not a secret anymore!