This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
A servlet is laid out perfectly to handle the control flow in a web programming evironment. It's method names make everything very self evident. Building the output stream, however, is cumbersome in a servlet. It involves typing 'out.println' over and over again.
JSP (especially now, with EL and JSTL) makes it possible for people with design skills but no understanding of Java to focus on look and feel in an evironment almost as simple as plain HTML pages. Controlling the flow, however, is cumbersome as all of the underlying servlet structure has been abstracted and buried in order to hide it and simplify things for those only concerned with appearance. [ May 16, 2005: Message edited by: Ben Souther ]
I think the best answer I can give to a question like this is to advise you to try coding your webapp by putting all of your presentation logic into servlet code rather than a JSP. Then, you'll realize very quickly why we use JSPs.
James Carman, President<br />Carman Consulting, Inc.
Some teams in my shop have these rules: Servlets are pure Java, no HTML and no output to the browser. JSPs are pure HTML and tags, no Java. This works out nicely with a Servlet controller, JSP view design.
No Java in JSP is pretty harsh, but if you can really do it the JSPs are much cleaner. My own project inherited a framework and architecture that uses Java in JSPs and it is painful at best. Given the chance, I'd adopt these rules next time around myself.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi