The use of scriptlets (those <% %> things) in JSP is indeed highly discouraged since the birth of taglibs. This is mainly because of the following reasons:

1) Scriptlets are not reusable 

Scriptlets are not object oriented

Scriptlets can not be unit-tested

Scriptlets require high maintainance and are not UI Designer friendly. It has to be maintained by a Java Developer

 

Below is an example which illustrates the use of Tag Lib in JSP.


<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

        
${product.name} ${product.description} ${product.price}

The above code is similar to iterating a list of products from a List/Array and displaying the name, description and price of the product in a HTML Table. The <c:forEach> tag in this case does the trick of iterating the list and works like a java for-loop. As it is clearly evident from the above example mentioned above, the use of tag-lig gives a XML style look and feel to the JSP and removes the unwanted java scriptets from the JSP. This gives the UI designers an easy approach to work more effectively on the design rather than the logic underlying below.


Related Posts:


Enter your email address:

Delivered by FeedBurner



Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)