My coworkers and I have found it very helpful to do HTML only in JSPs, and Java code only in Java. We have been using JSTL in JSPs to access beans created in Servlets (or objects working in conjunction with servlets).
All requests are dispatched through some objects which process the request and provide display data for the JSPs via request or session attributes. The JSPs job is to format the data and display it.
JSPs are included after java using:
RequestDispatcher dispatcher = request.getRequestDispatcher(jspPage);
dispatcher.include(request, response);
Generally, jsps are not requested directly...actually never in our case.
We configure which Java code to execute and which JSP(s) to include using XML.
So, that's no <% in the jsp and no println() in the java. JSPs do iterate and may contain some JSTL scripting. Using only JSTL keeps it to a optimal level. (No jstl sql. Sql is only for Java.)
Some of my coworkers don't know any Java, but can help immensely on the projects and are much better at asthetics than I am. Once they do a few pages with JSTL, they are on their way! We are able to work together efficiently and happily. It's a lot of fun!
I am not sure if it provides the best raw performance per page, but it definitely makes thing more scalable as far as managing a project goes. It makes the presentation layer very flexible and independent, makes it easy to adjust the Java implementation when performance bottlenecks are found, and makes it much easier to test the Java using
JUnit. (It could be argued that using Java in any way will never provide the best raw performance, but I would never argue that
.)
(I think this whole concept is also one of the goals of Struts...and they probably explain it much better than I can. Sun's documentation on the dispatcher model, and other models, for web applications is helpful too.)
PS: Well...maybe some resp.getOutputStream().write() in the java when generating non-html, such as PDF. (Cocoon might help, maybe?)