• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doPost() processes - doGet() displays

 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

-Nate
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Odd. I have. Maybe it just got less popular after JSPs and MVC-patterned app structures took over.
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Amir Kamran
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic