JSP Tag Library (JSTL)
JSP Disadvantage
1. Java code embedded in scriptlets make the
code difficult to understand
2. Reduced code reusability
3. Difficult to modify [Java Code]
4. Java code needs to use Class Casting
JSTL Advantages
1. Better code
2. Enhanced Code reusability
3. No type casting from the request and session objects
4. Expression Language in JSP makes it easier to call getter and setter methods.
Drawback
1. Adds overhead as JSTL adds more into the resultant Servlet
2. Can not do all that Java code can do
Four Libraries:
Core: Basic tags like loops, conditions, and input/output
fmt: Format like date format
xml: XML processing
sql: Database access
Core Tag Library
<%@ taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core" %>
<core:set var="var" scope="session" value="..."/>
Conditional
<core:if test="${condition}"> </core:if>
<core:choose>
<core:when test="condition1" >
...
</core:when>
<core:when test="condition2" >
...
</core:when>
<core:otherwise>
</core:otherwise>
</core:choose>
<core:otherwise> will be executed only and if only all other conditions fail.
Iterator
Iterator tages are used to traverse an array of objects and process each object (when required)
<c:forEach var="item" items="collection">
</c:forEach>
or
<c:forEach begin="0" end="10" varStatus="status" step="1" >
</c:forEach>
Function Tag Library
Basic String Functions
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
Example
<%@ taglib uri="/WEB-INF/fn.tld" prefix="fn" %>
<%@ taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core" %>
<core:set var="test" value="Hello World"/>
Index of l is :- ${fn:indexOf(test, "l")}<br>
From: http://sitestree.com/?p=4792
Categories:37
Tags:
Post Data:2007-12-05 06:15:58
Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a>
In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
<a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>
