End of the road for Scriplets?
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?
Follow this link for more discussion on this topic –
http://javalobby.org/thread.jspa?messageID=91814972&threadID=15046&forumID=61
Read the article by Bear Bibeault at:
http://www.javaranch.com/journal/200408/Journal200408.jsp#a3
He’s all for scriptless JSPs.