My first exposure to servlets was a little over 2 years ago and to JSP even more recently than that. I think I've picked up a lot about what constitutes best practice in constructing a web app today but I'm interested to know how things have developed historically.
I've come across code using servlets exclusively to serve content; JSP with scriptlets but no custom tags; JSP with custom tags but no JSTL; JSP with JSTL; and lastly JSP with Struts. I've not yet cast more than an interested glance at JavaServer Faces.
Once JSTL enters the fray best practice is pretty clear to me. However, I'd like to know what went before. Specifically what was considered the cleanest way to present the contents of a SQL ResultSet in a JSP page. I guess looping through some sort of Collection of beans is the best I can come up with. Presumably with the addition of taglibs in JSP 1.1 you could define your own forEach tag if you felt so inclined.
I'd appreciate it if anyone can point me to a reference example or, if sufficiently confident, provide some of their own code as an illustration of best practice with JSP 1.0 or 1.1. I've trawled around the web a bit but I've not found anything that looks particularly slick.
Thanks for your time.
What do you want to know? I'm not in a position to post older code, either because I no longer have access to it, it no longer exists, or is proprietary.
1) Servlet controller obtains POJO collection from model classes -- all SQL and result set handling hidden by UI-agnostic model.
2) Controller places collection on request and forwards to JSP
3) JSP uses scriplets and scriplet expressions to iterate over collection and display values
The only chnage I've made is that now the scriptless JSP pages use JSTL and EL (as well as app-specific custom tags as necessary) to replace the scriplet iteration and conditionals as well as the scriplet expressions. In many cases I've had to adjust the API of the POJO value objects being sent to the page to make them "EL-friendly" (in other words, strictly bean-patterned or an implementor of Map).
[ September 08, 2004: Message edited by: Bear Bibeault ]
I think I'll complete my example and post it here as I feel there are quite a few Ranchers who aren't yet using JSTL or even MVC who would hopefully benefit from a simplified example.
I'm a little unsure of my terminology here; does your Collection contain value objects or is it a value object itself? Also, what would it be a collection of?
Depends upon circumstances. It could be as generic as Object (as I just posted in another topic) when the JSP page doesn't need to know anything about the data, but is frequently either a List or array of POJO value objects (to preserve order).
(Sorry if this is a really dumb question...)
With jsp2.0 I should be able to do away with everything, is that correct?
but I'm worried about performance.
I would take one of your more complex pages and convert it. Measure the performance to see if it suits your needs. I have done no quantitative measuring since I have not felt the need to, having noticed no qualitative performance issues.
[ September 12, 2004: Message edited by: dennis he ]