Upload
hoc-lap-trinh-web
View
1.318
Download
4
Embed Size (px)
DESCRIPTION
Citation preview
Slide 1 of 21
JSP Standard Tag Library
Slide 2 of 21
Overview JSTL Core Tag Library Methods using EL I18N & Formatting Tag Library SQL Tag Library XML Tag Library
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
Slide 4 of 21
JSTL - Types
JSP Standard Tag Library (JSTL)
Core Tag Library
I18N & Formatting Tag Library
SQL Tag Library
XML Tag Library
Slide 5 of 21
Core Tag Library
Core Tag Library
General Purpose Tags
Decision Making Tags
Iteration Tags
set remove out forEach forTokensif choose
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” />
Slide 7 of 21
General-purpose tags-Example
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
Slide 9 of 21
if tags
Slide 10 of 21
choose tags
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>
Slide 12 of 21
Iteration tags - Example
Slide 13 of 21
SQL Tag Library
SQL Tag Library
setDataSource query update paramtransaction
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” />
Slide 15 of 21
SQL Tag Library – query tag– <sql:query var=“varName” dataSource=“datasource”
scope=“page | request | session | application”>
SQL Statement
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>
Slide 17 of 21
SQL Tag Library – transaction tag– <sql:transaction dataSource=“datasource”
isolation=“isolationLevel”>• <sql:update> or <sql:query> Statements
– </sql:transaction>
Slide 18 of 21
SQL Tag Library – transaction tag
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>
Slide 20 of 21
Summary
JSTL Core Tag Library
– General purpose Tags– Decision making Tags– Iteration Tags
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