DEV Community

Cover image for Why encourage to use JSTL in your legacy projects over JSP scriptlet?
Paladuta Stefan
Paladuta Stefan

Posted on • Updated on

Why encourage to use JSTL in your legacy projects over JSP scriptlet?

This article will be a short and will represent maybe just a memo on why you as Team Leader should impose (or encourage) to your team the use of JSTL or/and even migrate piece by piece your current JSP’s written with scriptlet into JSTL syntax.

The arguments:

The human nature

If we write or maintain the .jsp pages in scriptlet code, believe me when I say that because of stressful situations (deadlines on projects or on features) or maybe because of commodity lot of things will be done in dumb ways. When I say dumb ways I mean that you will end up after a lot of time with a tone of things in FrontEnd written in .jsp as scriptlet that for sure should have been done in BackEnd. An example that I always saw in my time is that a lot of collections are sent in FrontEnd and the developer constructs a complete new collection from 0 and even does some calculations on it (that aren’t advanced but for sure they have no place in FrontEnd in this architecture).

Using jstl syntax is very limited (that’s the beauty) will impose to the developers to stop putting everything in FE and start thinking what should the BE provide already. Meanwhile the FE with the jstl will do small things in his limitation like iteration, conditional check, formatting some data, etc. nothing crazy that the classic scriptlet would have done.

Visually pleasant

I don’t know about you but I never saw in my company on the legacy application (that is over 15 years) code written in .jsp that doesn’t do crazy stuff ([…] the worst I seen his connection to DB, recovery of data , transforming that data, displaying that data […]) and looks ugly. Instead after 1 years of putting my team to try to use jstl when possible some pages for us developers are now more clearer (even found old bugs).

BAD:

<html>
  <head>
    <title>Count to 10 in JSP scriptlet</title>
  </head>
  <body>
    <%
    for(int i=1;i<=10;i++)
    {%>
     <%=i%><br/>
     <%
     }
     %>
  </body>
</html>
Enter fullscreen mode Exit fullscreen mode

NICE:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
 <head>
  <title>Count to 10 Example (using JSTL)</title>
 </head>

 <body>
  <c:forEach var="i" begin="1" end="10" step="1">
   <c:out value="${i}" />
   <br />
  </c:forEach>
 </body>
</html>
Enter fullscreen mode Exit fullscreen mode

What is the cost ?

For you as developers ? nothing because we should know to do this, writing clean code instead of bad code shouldn’t even be an argument.

For the client ? if we don’t have experience in JSTL well some patience.

REMEMBER: Let the service layer have the business logic and determine what data the JSP needs.


If you liked the article please take a minute to offer me a clap 👏 or even buy me a coffee https://www.buymeacoffee.com/stefansplace (;

Based on the number of claps I will know if writing some tricks about this old concept is still wanted.

My main article: https://medium.com/@stefan.paladuta17/why-to-encourage-to-use-jstl-in-your-legacy-projects-over-jsp-scriptlet-4dd36e95ce00

Top comments (0)