Session 7 : jstl - Giáo trình Bách Khoa Aptech

1,413 views

Published on

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

Session 7 : jstl - Giáo trình Bách Khoa Aptech

  1. 1. Slide 1 of 21 JSP Standard Tag Library
  2. 2. Slide 2 of 21 Overview  JSTL  Core Tag Library  Methods using EL  I18N & Formatting Tag Library  SQL Tag Library  XML Tag Library
  3. 3. Slide 3 of 21 JSTL  Custom tags provide a way to reuse valuable components  JSTL has reusable standard set of tags.  Provides the user with a script-free environment  User can write code using tags instead of Java code and scriptlets  JSTL tags are easier for non-programmers and inexperienced programmers
  4. 4. Slide 4 of 21 JSTL - Types JSP Standard Tag Library (JSTL) Core Tag Library I18N & Formatting Tag Library SQL Tag Library XML Tag Library
  5. 5. Slide 5 of 21 Core Tag Library Core Tag Library General Purpose Tags Decision Making Tags Iteration Tags set remove out forEach forTokensif choose
  6. 6. Slide 6 of 21 General-purpose tags  <%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %> – <c:set var=“varName” value=“value” scope=“page|request|session|application” /> – <c:remove var=“varName” scope=“page| request|session|application” /> – <c:out value=“value|expression” escapeXml=“true|false” default=“defaultValue” />
  7. 7. Slide 7 of 21 General-purpose tags-Example
  8. 8. Slide 8 of 21 Decision-making tags – <c:if test =“testcondition” var=“varName” scope=“page | request | session | application”> Body content – </c:if> – <c:choose> <c:when test=“testCondition”> Body Content </c:when> <c:otherwise> Body Content
  9. 9. Slide 9 of 21 if tags
  10. 10. Slide 10 of 21 choose tags
  11. 11. Slide 11 of 21 Iteration tags – <c:forEach var=“varName” item=“collection” begin=“begin” end=“end” step=“step”> Body Content – </c:forEach> – <c:forTokens items=“stringofToken” delims=“delimiters” var=“varName” > Body Content – </c:forTokens>
  12. 12. Slide 12 of 21 Iteration tags - Example
  13. 13. Slide 13 of 21 SQL Tag Library SQL Tag Library setDataSource query update paramtransaction
  14. 14. Slide 14 of 21 SQL Tag Library – setDataSource tag  <%@ taglib uri = "http://java.sun.com/jsp/jstl/sql" prefix = “sql" %> – <sql:setDataSource dataSource=“datasource” | url=“jdbcurl” driver=“jdbcclassdriver” user=“username” password=“password” var=“varName” scope=“page | request | session | application” />
  15. 15. Slide 15 of 21 SQL Tag Library – query tag – <sql:query var=“varName” dataSource=“datasource” scope=“page | request | session | application”> SQL Statement
  16. 16. Slide 16 of 21 SQL Tag Library – update tag – <sql:update var=“varName” dataSource=“datasource” scope=“page | request | session | application”> SQL Statement • <sql:param value=“value” /> – </sql:update>
  17. 17. Slide 17 of 21 SQL Tag Library – transaction tag – <sql:transaction dataSource=“datasource” isolation=“isolationLevel”> • <sql:update> or <sql:query> Statements – </sql:transaction>
  18. 18. Slide 18 of 21 SQL Tag Library – transaction tag
  19. 19. Slide 19 of 21 param Tag  Param is used to set values for parameters markers (“?”) in SQL statement  It acts as a sub tag for <sql:query> and <sql:update>
  20. 20. Slide 20 of 21 Summary  JSTL  Core Tag Library – General purpose Tags – Decision making Tags – Iteration Tags
  21. 21. Slide 21 of 21 Summary  Methods using EL  I18N & Formatting Tag Library – Locale, Bundle, Message – formatDate, formatNumber  SQL Tag Library – setDataSource – query – update – transaction – param

×