Friday, July 24, 2009

JSP vs JSTL

JSTL is java standard tag library. Trend of modern programming: it is not cool if it does not look like XML. (I beg to differ).

I found an excellent book covering features of Java. This is what copied right of there, about JSTL:



Using scriptlets

<html>
<head>
<title>simple example<title>
</head>
<body>
<%
for(int i=0; i<5; i++) {
%>
<%= i %> <br/>
<% } %>
</body>
</html>
The above JSP code is hard to read and maintain.

Using JSTL tags
<%@ taglib prefix=”c”
uri=”http//java.sun.com/jstl/core”>
<html>
<head><title>simple example<title></head>
<body>
<c:forEach var=”i” begin=”1” end=”5” step=”1”>
<c:out value=”${i}”> <br/>
</c:forEach>
</body>
</html>
The above JSP code consists entirely of HTML & JSTL tags (in bold).


About the comment in the left: I BEG TO DIFFER.
Look, JSP looks like java, and it should be.

No comments: