aspose file tools*
The moose likes JSP and the fly likes Best practice before taglibs and JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Best practice before taglibs and JSTL" Watch "Best practice before taglibs and JSTL" New topic
Author

Best practice before taglibs and JSTL

Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Hi folks,

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.

Jules
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Having been working with JSP since 0.92, I've been through it all. From putting all the Java, SQL and all, on the JSP page -- boy, I learned not to do that quickly, through migrating the Java into beans (a la Model 1), through migrating the Java into Servlet controllers (aka Model 2), through present-day JSTL/EL scriptless pages.

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
I guess my question is what was considered the cleanest way to present the contents of a SQL ResultSet in a JSP page prior to the advent of JSTL and taglibs? Can anyone offer a code example or a link to one?

Perhaps I should tidy up my effort and post it for review.

Jules
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

What I did in the Model 2 phase, which is where I think your question lies on my "timeline", was roughly:

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 ]
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Thanks Bear. That's the architecture I had in mind. 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? I'm thinking of a List of beans; I don't quite see how a Map fits for a ResultSet with multiple rows and columns.

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.

Jules
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

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).
John Dunn
slicker
Ranch Hand

Joined: Jan 30, 2003
Posts: 1108
Bear,
How fast is JSTL, custom tags, and EL as opposed to vanilla JSP scriplets?
Are there benefits to the former besides just make the developer spend less time coding near the html??


"No one appreciates the very special genius of your conversation as the dog does."
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

I find the scriptless pages much easier to extend, maintain and refactor than even I expected. I have noticed no discernable performance difference.
John Dunn
slicker
Ranch Hand

Joined: Jan 30, 2003
Posts: 1108
I'm using Tomcat 5 with legacy code that contains .css files, javascript, shareable js objects for dynamic updates and java scriptlets. With jsp2.0 I should be able to do away with everything, is that correct? I ~may~ keep the css around b/c another group manages the stylesheets. I'd like to move on to the lastest stuff, but I'm worried about performance. Note, 30-40ms slower would be too slow. Do you think it worth the effort?


Also the architecture I inherited has a frame with one input box and a submit button. Output get displayed to a frame below. How reliable is IFrame with a jsp page? Will this get rid of alot of the javascript code to navigate between frames? Right now we ONLY use the top frame for userInput.

(Sorry if this is a really dumb question...)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

With jsp2.0 I should be able to do away with everything, is that correct?


No, like JSP 1.2, JSP 2.0 is a server-side technology. Your pages will still consist of HTML, Javascript and CSS as client-side technology.

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.

How reliable is IFrame with a jsp page? Will this get rid of alot of the javascript code to navigate between frames?


iframes are a client-side concept. As such, JSP or not is moot. You will still need any Javascript to perform any client-side actions. I've used iframes a fair amount with little in the way of difficulties -- none of them related to JSP.
dennis he
Greenhorn

Joined: Sep 09, 2004
Posts: 1
The JSP2.0 import a new language(EL),you can implement all works by it,you must use scriptle to finish logic handle before jsp1.2 appeared,it isn't easy maintain,readability,refactory,so if you will using taglibs and JSTL,that's a good idea!
[ September 12, 2004: Message edited by: dennis he ]

nothing at all
 
wood burning stoves
 
subject: Best practice before taglibs and JSTL