Basic JSTL

1,757 views
1,677 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,757
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
41
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Basic JSTL

  1. 1. Core JSTL Cornelius Koo, ST JavaSchool 2005Jl. Cemara 2/20, Salatiga
  2. 2. Copy The Libraries
  3. 3. Don’t Forget The Taglib<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  4. 4. <c:out>
  5. 5. <c:out value=Hello World/> out.jsp
  6. 6. <c:forEach>
  7. 7. <table> <c:forEach var="movie" items="${movieList}" varStatus="movieLoopCount"> <tr> <td>${movieLoopCount.count}</td> <td>${movie}</td> </tr> </c:forEach></table> forEach.jsp
  8. 8. <c:if>
  9. 9. <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
  10. 10. <c:choose>, <c:when>, <c:otherwise>
  11. 11. <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
  12. 12. <c:set>
  13. 13. var for Attribute
  14. 14. <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
  15. 15. target for Map
  16. 16. <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
  17. 17. <c:remove>
  18. 18. <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
  19. 19. <c:import>
  20. 20. • It can be use to include static page from outside the web-container.
  21. 21. <c:import url=“http://www.google.com/index.html”/> import.jsp
  22. 22. <c:param>
  23. 23. <c:import url="action_header.jsp"> <c:param name="title" value="This is the headers title"/></c:import> body.jsp
  24. 24. <c:url>
  25. 25. <a href="<c:url value=/jstl/inputComments.jsp/>"> Click Here </a> url.jsp
  26. 26. <c:catch>
  27. 27. <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
  28. 28. JSTL Validator
  29. 29. <%@ 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 wont"); --%></body></html> jsp/validated.jsp

×