postheadericon JSTL standard tag library Example

index.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<HTML>
<HEAD>
<TITLE>WTAD: Ex31 : www.BipinRupadiya.com</TITLE>
</HEAD>
<BODY>
<h3>Example of JSTL standard tag library.</h3>
<ul>
<li><a href="set.jsp">set, remove and out</a></li>
<!-- Example of c:for -->
<li><a href="for.jsp">for</a></li>
<!-- Example of c:if -->
<li><a href="if.jsp">if</a></li>
<!-- Example of c:choose -->
<li><a href="choose.jsp">choose</a></li>
<!-- Example of c:redirect and c:param -->
<li><a href="redirect.jsp">redirect</a></li>

</ul>
</BODY>
</HTML>




set.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<HTML>
<HEAD>
<TITLE><c:out value="<c:set>, <c:remove> Tags"/></TITLE>
</HEAD>
<BODY>
<H1 ALIGN="CENTER">
<CODE><c:out value="<c:set>, <c:remove> Tags"/></CODE>
</H1>
<c:set var="map" value="<%= new java.util.HashMap() %>" scope="request"/>
<c:set target="${map}" property="partialTitle" value="<read-it>Core</read-it>"/>
<c:set target="${map}" property="fullTitle">
<c:out value="${map.partialTitle}"/> <BR> Servlets and JSP Volume 2 </c:set>
<H1 ALIGN="CENTER">${map.fullTitle}</H1>
<c:set var="authors" value="Marty Hall, Larry Brown, Yaakov Chaikin" scope="request"/>
<c:set var="authors">Authors</c:set>
<H2 ALIGN="CENTER">${authors}: ${requestScope.authors}</H2>
<c:remove var="authors"/>
<H2 ALIGN="CENTER">${pageScope.authors}: ${requestScope.authors}</H2>
</BODY>
</HTML>



for.jsp

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

<HTML>
<HEAD>
<TITLE><c:out value="<c:foreach>, <c:forTokens> Tags"/></TITLE>
</HEAD>
<BODY>
<H1 ALIGN="center">
<CODE><c:out value="<c:foreach>, <c:forTokens> Tags"/></CODE>
</H1>

<TABLE>
<TR>
<TD>
<UL>
<c:forEach var="i" begin="1" end="10" step="2">
<LI>i = ${i}</LI>
</c:forEach>
</UL>
</TD>
<TD>
<%
java.util.List list = new java.util.ArrayList();
list.add("One");
list.add("Two");
list.add("Three");
list.add("Four");
list.add("Five");
request.setAttribute("list", list);
%>
<UL>
<c:forEach var="item" items="${list}">
<LI>${item}</LI>
</c:forEach>
</UL>
</TD>
<TD>
<UL>
<!--forTokens sperat string by special symboles in delims atributes-->
<c:forTokens var="item" items="<Once)Upon,A(Time%There...>" delims="<),A(%>">
<LI>${item}</LI>
</c:forTokens>
</UL>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>

if.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<HTML>
<HEAD>
<TITLE><c:out value="<c:if> Tags"/></TITLE>
</HEAD>
<BODY>
<H1 ALIGN="center"><CODE><c:out value="<c:if> Tag"/></CODE></H1>
<UL>
<c:forEach var="i" begin="1" end="10" step="2">
<LI>
i = ${i}
<c:if test="${i > 3}">
(greater than 3)
</c:if>
</LI>
</c:forEach>
</UL>
</BODY>
</HTML>



choose.jsp

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

<HTML>
<HEAD>
<TITLE><c:out value="<c:choose>, <c:when>, <c:otherwise> Tags"/></TITLE>
</HEAD>
<BODY>
<H1 ALIGN="center">
<CODE><c:out value="<c:choose>, <c:when>, <c:otherwise> Tags"/></CODE>
</H1>

<UL>
<c:forEach var="i" begin="1" end="10">
<LI>i = ${i}
<c:choose>
<c:when test="${i < 3}">(less than 3)</c:when>
<c:when test="${i < 5}">(less than 5)</c:when>
<c:when test="${i == 5}">(It IS 5! SO exciting!)</c:when>
<c:otherwise>(greater than 5)</c:otherwise>
</c:choose>
</LI>
</c:forEach>
</UL>
</BODY>
</HTML>



redirect.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:redirect url="http://www.google.com/search">
<c:param name="hl" value="en"/>
<c:param name="q">Bipin Rupadiya</c:param>
</c:redirect>

0 comments:

Blog Archive

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.