JSTL-CORE -Tags
JSTL Core - Tags Tutorial
JSPHome
In JSTL Core, there are different groups of tags available. These tags allow performing core functionalities such as printing messages, comparing values, looping through the nodes etc.
These core tags categorized into 4 groups.
1. Conditional Tags
2. Iteration Tags
3. URL Management
4. General purpose.
In this tutorial, we are going to learn how to use them. Here are some example programs which will demonstrates the using of different tags.
1. Conditional Tags
<c:if> <c:choose> <c:when> <c:otherwise>
demo3.jsp
<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<body bgcolor=lightblue>
<form method=post action=demo3.jsp>
<select name="combo1">
<option value="aaa">AAA
<option value="bbb">BBB
</select>
<input type=submit>
</form>
<c:set var="s" value="${param.combo1}" />
<c:out value="${s}" />
<br>
<c:if test="${s eq 'aaa' }" >
<c:out value="Good Morning...SAM!" />
</c:if>
<c:if test="${s == 'aaa'}">
<c:out value=" How Are You?....TOM!" />
</c:if>
</body>
</html>
<c:choose >
<c:when test=" " >
<c:otherwise> something </c:otherwise>
</c:choose>
// demo4.jsp
<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<body bgcolor=lightblue>
<form method=post action="demo3.jsp">
<select name="combo1">
<option value="1">1 </option>
<option value="2">2 </option>
<option value="3">3 </option>
<option value="4">4 </option>
<option value="5">5 </option>
<option value="7">7 </option>
</select>
<input type=submit>
</form>
<c:set var="s" value="${param.combo1}" />
Today is
<br>
<font size=24 color=red>
<c:choose>
<c:when test="${s==1}">Sunday </c:when>
<c:when test="${s==2}">Monday</c:when>
<c:when test="${s==3}">Tuesday</c:when>
<c:when test="${s==4}">Wednesday</c:when>
<c:when test="${s==5}">Thursday</c:when>
<c:otherwise>
select between 1 & 5
</c:otherwise>
</c:choose>
</body>
</html>
IterationTags
<c:forEach> <c:forTokens>
URL management
<c:import> <c:param> <c:redirect> <c:url>
General purpose
<c:out> <c:catch>
Comments
Post a Comment