Maybe I am being a purist but I would like to avoid all Java code (scriplets) in my JSPs and use tags like JSTL, as far as possible. Nothing good comes from Java code in JSP pages.
So how do we access database tables in JSP? I believe that it’s perfectly okay to use <sql:query> in JSP pages for a very simple applications, but when the applications get larger and more complex, there’s lot to be gained by adding abstractions and isolating database access in separate classes. You shouldn’t put database code in JSPs and accessing Hibernate (for example) directly in a JSP page through a tag library doesn’t pass my test for what’s adviceable. Use the MVC 2 pattern and learn to separate your presentation logic from your business logic (Some good MVC 2 frameworks are Spring and Struts). That said, you can use all the JSTL (and custom) tag libraries to access properties of your data objects (managed by Hibernate) in the JSP pages. There are examples of this in the Hibernate documentation. The actual interaction with Hibernate, however, is better done by something like Struts Action objects or JSF action methods/listeners.
I would like to hear arguments for and against the usage of scriplets in JSP code. Why does the SCWCD 1.4 examination still ask questions on Scriplets?