End of the road for Scriplets?

Discussions

Industry news: End of the road for Scriplets?

  1. End of the road for Scriplets? (1 messages)

    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.

    Why does the SCWCD 1.4 examination still ask questions on Scriplets? I would like to hear arguments for and against the usage of scriplets in JSP code.
  2. Re:End of the road for Scriplets?[ Go to top ]

    Why does the SCWCD 1.4 examination still ask questions on Scriplets? I would like to hear arguments for and against the usage of scriplets in JSP code.

    Hi,

    There are multiple reasons for this.
    1. Most simple applications and even many pages in a complex application do not need the overhead of other frameworks like struts.
    2. There are many legacy applications that make extensive use of JSP scriptlets in the code.
    3. Learning Scriptlets is still the easiest way for newbies to understand the JSP concept. There is a steep learning curve when jumping straight into a framework. Additionally, there are so many frameworks coming that make it hard for any developer to understand their relative merits and demerits (Hibernate, velocity etc still have their usual meanings for me :) )

    Regards
    SherlockSridhar