Upload
corneliuskoo
View
1.491
Download
3
Tags:
Embed Size (px)
Citation preview
Core JSTL
Cornelius Koo, ST
JavaSchool
2005
Jl. Cemara 2/20, Salatiga
Copy The Libraries
Don’t Forget The Taglib
<%@ taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %>
<c:out>
<c:out value='Hello World'/>
out.jsp
<c:forEach>
<table>
<c:forEach var="movie" items="${movieList}" varStatus="movieLoopCount">
<tr>
<td>${movieLoopCount.count}</td>
<td>${movie}</td>
</tr>
</c:forEach>
</table>
forEach.jsp
<c:if>
<c:if test="${param.user eq 'Member'}">
<jsp:include page="inputComments.jsp"
flush="true"/>
</c:if>
<c:if test="${param.user eq 'Non-Member'}">
<jsp:include page="suggestion.jsp"flush="true"/>
</c:if>
<c:if test="${empty param.user}">
<c:out value='Give your choice...'/>
</c:if> if.jsp
<c:choose>, <c:when>,
<c:otherwise>
<c:choose>
<c:when test="${param.level == 'insane'}">
All enemy heroes are 200% stronger
</c:when>
<c:when test="${param.level == 'normal'}">
All enemy heroes are have the same power level compared to yours
</c:when>
<c:when test="${param.level == 'easy'}">
Your hero will be the strongest
</c:when>
<c:otherwise>
You have to choose your game level
</c:otherwise>
</c:choose>
choose.jsp
<c:set>
var for Attribute
<c:set var="level" scope="session"
value="insane"/>
Level: ${level}
<c:set var="player" scope="session">
Zaradaz
</c:set>
<br/>
Players : ${player}
set-var.jsp
target for Map
<jsp:useBean id="person" class="jsp.example.bean.Employee"/>
<jsp:setProperty name="person" property="name" value="John"/>
<c:set target="${person}" property="address" value="Dipo 64"/>
<c:set target="${person}" property="age">
55
</c:set>
<br/>
Name : ${person.name}
<br/>
Address : ${person.address}
<br/>
Age : ${person.age}
set-target.jsp
<c:remove>
<c:set var="level" scope="session" value="insane"/>
Level: ${level}
<c:set var="player" scope="session">
Zaradaz
</c:set>
<br/>
Players : ${player}
<c:remove var="player" scope="session"/>
<br/>
Players is now : ${player} set-var.jsp
<c:import>
• It can be use to include static page from
outside the web-container.
<c:import
url=“http://www.google.com/index.html”
/>
import.jsp
<c:param>
<c:import url="action_header.jsp">
<c:param name="title" value="This is the
header's title"/>
</c:import>
body.jsp
<c:url>
<a href="<c:url value='/jstl/inputComments.jsp'/>">
Click Here </a>
url.jsp
<c:catch>
<c:catch var="userException">
<% int x = 1/0; %>
There is no error...
</c:catch>
<c:if test="${userException != null}">
There was an exception : ${userException.message}
</c:if>
<br/>
Done catch.jsp
JSTL Validator
<%@ taglib uri='WEB-INF/tlds/restrictJavaCode.tld' prefix='rjc' %>
<%@ taglib uri='WEB-INF/tlds/restrictTaglibs.tld' prefix='rtl' %>
<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c' %>
<html>
<head>
<title>Test Validator</title>
</head>
<body>
<c:out value='This one will pass the test...'/>
<%-- out.println("This one won't"); --%>
</body>
</html>
jsp/validated.jsp