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.
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...
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.