• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Best practice before taglibs and JSTL

 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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).
 
slicker
Posts: 1108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic