30
Core JSTL Cornelius Koo, ST JavaSchool 2005 Jl. Cemara 2/20, Salatiga

Basic JSTL

Embed Size (px)

Citation preview

Page 1: Basic JSTL

Core JSTL

Cornelius Koo, ST

JavaSchool

2005

Jl. Cemara 2/20, Salatiga

Page 2: Basic JSTL

Copy The Libraries

Page 3: Basic JSTL
Page 4: Basic JSTL

Don’t Forget The Taglib

<%@ taglib prefix="c"

uri="http://java.sun.com/jsp/jstl/core" %>

Page 5: Basic JSTL

<c:out>

Page 6: Basic JSTL

<c:out value='Hello World'/>

out.jsp

Page 7: Basic JSTL

<c:forEach>

Page 8: Basic JSTL

<table>

<c:forEach var="movie" items="${movieList}" varStatus="movieLoopCount">

<tr>

<td>${movieLoopCount.count}</td>

<td>${movie}</td>

</tr>

</c:forEach>

</table>

forEach.jsp

Page 9: Basic JSTL

<c:if>

Page 10: Basic JSTL

<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

Page 11: Basic JSTL

<c:choose>, <c:when>,

<c:otherwise>

Page 12: Basic JSTL

<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

Page 13: Basic JSTL

<c:set>

Page 14: Basic JSTL

var for Attribute

Page 15: Basic JSTL

<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

Page 16: Basic JSTL

target for Map

Page 17: Basic JSTL

<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

Page 18: Basic JSTL

<c:remove>

Page 19: Basic JSTL

<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

Page 20: Basic JSTL

<c:import>

Page 21: Basic JSTL

• It can be use to include static page from

outside the web-container.

Page 22: Basic JSTL

<c:import

url=“http://www.google.com/index.html”

/>

import.jsp

Page 23: Basic JSTL

<c:param>

Page 24: Basic JSTL

<c:import url="action_header.jsp">

<c:param name="title" value="This is the

header's title"/>

</c:import>

body.jsp

Page 25: Basic JSTL

<c:url>

Page 26: Basic JSTL

<a href="<c:url value='/jstl/inputComments.jsp'/>">

Click Here </a>

url.jsp

Page 27: Basic JSTL

<c:catch>

Page 28: Basic JSTL

<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

Page 29: Basic JSTL

JSTL Validator

Page 30: Basic JSTL

<%@ 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