SlideShare a Scribd company logo
JSP Standard Tag Library(JSTL)
JSP Standard Tag Library
• Introduction to JSTL
• Exploring the features of JSTL
• Working with core Tag Library
• Working with SQL Tag library
Introduction to JSTL
•Contains Standard tag library
•Library is available in all compliant containers
•Wide range of custom action functionality
•Readability and Maintainability
Function Overview of JSTL
•Core functionality
•XML Manipulation
•SQL
•Internationalization and Formatting
•Note
•Makes use of expression language
JSTL expression language
• Accessed via ${expression}
• Provides shorthand notation to access
- Attributes of standard servlet Objects
- Bean properties
- Map,List and Array Element
• Standard part of JSP 2.0
- In JSTL EL can be used only in attributes
- In JSP 2.0 EL can ne used anywheres
Logic tags
• One choice: if
<c:if test="${someTest}“>Content
</c:if>
• Lots of choices: choose
<c:choose>
<c:when test="test1">Content1</c:when>
<c:when test="test2">Content2</c:when>
<c:when test="testN">ContentN</c:when>
<c:otherwise>Default Content</c:otherwise>
</c:choose>
Caution: resist use of business logic!
The “if” tag
<%@ taglib prefix="c” uri="http://java.sun.com/jstl/core" %>
<UL>
<c:forEach var="i" begin="1" end="10">
<LI><c:out value="${i}"/>
<c:if test="${i > 7}">
(greater than 7)
</c:if>
</c:forEach>
</UL>
“Choose” tag
<%@ taglib prefix="c” uri="http://java.sun.com/jstl/core" %>
<UL>
<c:forEach var="i" begin="1" end="10">
<LI><c:out value="${i}"/>
<c:choose><c:when test="${i < 4}">
(small)
</c:when><c:when test="${i < 8}">
(medium)
</c:when>
<c:otherwise>
(large)
</c:otherwise>
</c:choose>
</c:forEach></UL>
Database Access Tag
• <sql:setDataSource>
- Specifies data source (can also be set by config
settings)
• <sql:query>
- Queries database and stores ResultSet in variable
- Warning: this usage violates rule of keeping
business logic out of presentation layer. Instead, do
database access in servlet and pass results to JSP
via MVC.
Database Access Tag
• <sql:update>
• <sql:param>
• <sql:dateParam>
• <sql:transaction>
- Performs the enclosed <sql:query> and
<sql:update>actions as a single transaction
sql:setDataSource
• You can set a data source globally via configuration settings or
application-scoped variables.
Preferred approach in real applications
Or, you can set it on a specific page
<%@ taglib prefix="sql” uri="http://java.sun.com/jstl/sql" %>
<sql:setDataSource driver=“com.mysql.jdbc.Driver"
url=“jdbc:mysql://localhost:3306/test” user=“root"
password=“root"/>
sql:query
• Form 1: use the sql attribute
- <sql:query var="results" sql="SELECT *
FROM …"/>
• Form 2: put the query in the body of the tag
- <sql:query var="results“>
- SELECT * FROM …
- </sql:query>
sql:query
• Options
- dataSource
- maxRows
- startRow
• Caution
- Embedding SQL directly in JSP may be hard to
maintain
Simple Example
<%@ taglib prefix="c"
uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="sql"
uri="http://java.sun.com/jstl/sql" %>
<sql:setDataSource
driver=“com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test"
user=“root"
password=“root"/>
Simple Example Continued
<sql:query var="employees">
SELECT * FROM employees
</sql:query>
<UL>
<c:forEach var="row" items="${employees.rows}">
<LI><c:out value="${row.firstname}"/>
<c:out value="${row.lastname}"/>
</c:forEach>
</UL>
URL-Handling Tags
• <c:import>
- Read content from arbitrary URLs
• Insert into page
• Store in variable
• Or make accessible via a reader
- Unlike <jsp:include>, not restricted to own system
• <c:redirect>
- Redirects response to specified URL
• <c:param>
- Encodes a request parameter and adds it to a URL
- May be used within body of <c:import> or <c:redirect>
Summary
• JSTL is similar to the old Struts looping and logic tags
• JSTL is standardized, but not a standard part of JSP 1.2 or 2.0
- It must be downloaded and installed separately
• Supports a concise expression language
- Lets you access bean properties and implicit objects
- EL is standard part of JSP 2.0
• Looping tags
- Explicit numeric values
- Arrays, collections, maps, strings, etc.
• Conditional evaluation tags
- Single options
- Multiple options

More Related Content

PPT
Chap4 4 2
PDF
Basic JSTL
KEY
Data Abstraction for Large Web Applications
PDF
The Lumber Mill Xslt For Your Templates
TXT
Connection
PDF
10 jdbc
PPT
SQLITE Android
PPTX
Demystifying share point site definitions SharePoint 2007
Chap4 4 2
Basic JSTL
Data Abstraction for Large Web Applications
The Lumber Mill Xslt For Your Templates
Connection
10 jdbc
SQLITE Android
Demystifying share point site definitions SharePoint 2007

What's hot (20)

ODP
Running ms sql stored procedures in mule
PPTX
Jdbc Java Programming
PDF
Persitance Data with sqlite
PPSX
JSP - Part 1
PDF
Apache Con Us2007 Apachei Batis
 
PPTX
Qure Tech Presentation
PPTX
Advance java session 10
PPTX
Deploy and Manage the Infrastructure Using Azure Resource Manager
DOCX
Html To JSP
PPT
Jdbc
ODP
servlets and jsp
ODP
Sql lite android
PPTX
Backbonejs for beginners
PDF
Persistence with Ada Database Objects (ADO)
PPT
Persistences
PDF
Java >= 9
PPT
Grails Controllers
PPTX
Liquidating database frustrations with liquibase
PPTX
Rails application refactoring steps
PPTX
XSLT presentation
Running ms sql stored procedures in mule
Jdbc Java Programming
Persitance Data with sqlite
JSP - Part 1
Apache Con Us2007 Apachei Batis
 
Qure Tech Presentation
Advance java session 10
Deploy and Manage the Infrastructure Using Azure Resource Manager
Html To JSP
Jdbc
servlets and jsp
Sql lite android
Backbonejs for beginners
Persistence with Ada Database Objects (ADO)
Persistences
Java >= 9
Grails Controllers
Liquidating database frustrations with liquibase
Rails application refactoring steps
XSLT presentation
Ad

Similar to Advance java session 16 (20)

PDF
Lecture 5 JSTL, custom tags, maven
PDF
10 jdbc
PDF
Ch. 9 jsp standard tag library
PDF
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
PDF
13 java beans
PPTX
Implementing java server pages standard tag library v2
PPTX
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
PDF
15 expression-language
PPT
azuretip1detailshereforlearninganddoingpractice
PPT
Java .ppt
PPT
25.ppt
PDF
Ajax Tags Advanced
PPTX
JSTL.pptx
PDF
14 mvc
PPT
JSP Part 2
PDF
Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalache
PPT
Struts2-Spring=Hibernate
PPTX
Jsp and jstl
Lecture 5 JSTL, custom tags, maven
10 jdbc
Ch. 9 jsp standard tag library
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
13 java beans
Implementing java server pages standard tag library v2
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
15 expression-language
azuretip1detailshereforlearninganddoingpractice
Java .ppt
25.ppt
Ajax Tags Advanced
JSTL.pptx
14 mvc
JSP Part 2
Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalache
Struts2-Spring=Hibernate
Jsp and jstl
Ad

More from Smita B Kumar (19)

PPTX
Advance java session 20
PPTX
Advance java session 19
PPTX
Advance java session 18
PPTX
Advance java session 17
PPTX
Advance java session 15
PPTX
Advance java session 14
PPTX
Advance java session 13
PPTX
Advance java session 12
PPTX
Advance java session 11
PPTX
Advance java session 9
PPTX
Advance java session 8
PPTX
Advance java session 7
PPTX
Advance java session 6
PPTX
Advance java session 5
PPTX
Advance java session 4
PPTX
Advance java session 3
PPTX
Advance java session 2
PPTX
JEE session 1
PPTX
01 introduction to struts2
Advance java session 20
Advance java session 19
Advance java session 18
Advance java session 17
Advance java session 15
Advance java session 14
Advance java session 13
Advance java session 12
Advance java session 11
Advance java session 9
Advance java session 8
Advance java session 7
Advance java session 6
Advance java session 5
Advance java session 4
Advance java session 3
Advance java session 2
JEE session 1
01 introduction to struts2

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Encapsulation theory and applications.pdf
PPTX
Cloud computing and distributed systems.
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
20250228 LYD VKU AI Blended-Learning.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Encapsulation theory and applications.pdf
Cloud computing and distributed systems.
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Network Security Unit 5.pdf for BCA BBA.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Programs and apps: productivity, graphics, security and other tools
Mobile App Security Testing_ A Comprehensive Guide.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Understanding_Digital_Forensics_Presentation.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
sap open course for s4hana steps from ECC to s4
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx

Advance java session 16

  • 1. JSP Standard Tag Library(JSTL)
  • 2. JSP Standard Tag Library • Introduction to JSTL • Exploring the features of JSTL • Working with core Tag Library • Working with SQL Tag library
  • 3. Introduction to JSTL •Contains Standard tag library •Library is available in all compliant containers •Wide range of custom action functionality •Readability and Maintainability
  • 4. Function Overview of JSTL •Core functionality •XML Manipulation •SQL •Internationalization and Formatting •Note •Makes use of expression language
  • 5. JSTL expression language • Accessed via ${expression} • Provides shorthand notation to access - Attributes of standard servlet Objects - Bean properties - Map,List and Array Element • Standard part of JSP 2.0 - In JSTL EL can be used only in attributes - In JSP 2.0 EL can ne used anywheres
  • 6. Logic tags • One choice: if <c:if test="${someTest}“>Content </c:if> • Lots of choices: choose <c:choose> <c:when test="test1">Content1</c:when> <c:when test="test2">Content2</c:when> <c:when test="testN">ContentN</c:when> <c:otherwise>Default Content</c:otherwise> </c:choose> Caution: resist use of business logic!
  • 7. The “if” tag <%@ taglib prefix="c” uri="http://java.sun.com/jstl/core" %> <UL> <c:forEach var="i" begin="1" end="10"> <LI><c:out value="${i}"/> <c:if test="${i > 7}"> (greater than 7) </c:if> </c:forEach> </UL>
  • 8. “Choose” tag <%@ taglib prefix="c” uri="http://java.sun.com/jstl/core" %> <UL> <c:forEach var="i" begin="1" end="10"> <LI><c:out value="${i}"/> <c:choose><c:when test="${i < 4}"> (small) </c:when><c:when test="${i < 8}"> (medium) </c:when> <c:otherwise> (large) </c:otherwise> </c:choose> </c:forEach></UL>
  • 9. Database Access Tag • <sql:setDataSource> - Specifies data source (can also be set by config settings) • <sql:query> - Queries database and stores ResultSet in variable - Warning: this usage violates rule of keeping business logic out of presentation layer. Instead, do database access in servlet and pass results to JSP via MVC.
  • 10. Database Access Tag • <sql:update> • <sql:param> • <sql:dateParam> • <sql:transaction> - Performs the enclosed <sql:query> and <sql:update>actions as a single transaction
  • 11. sql:setDataSource • You can set a data source globally via configuration settings or application-scoped variables. Preferred approach in real applications Or, you can set it on a specific page <%@ taglib prefix="sql” uri="http://java.sun.com/jstl/sql" %> <sql:setDataSource driver=“com.mysql.jdbc.Driver" url=“jdbc:mysql://localhost:3306/test” user=“root" password=“root"/>
  • 12. sql:query • Form 1: use the sql attribute - <sql:query var="results" sql="SELECT * FROM …"/> • Form 2: put the query in the body of the tag - <sql:query var="results“> - SELECT * FROM … - </sql:query>
  • 13. sql:query • Options - dataSource - maxRows - startRow • Caution - Embedding SQL directly in JSP may be hard to maintain
  • 14. Simple Example <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> <%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %> <sql:setDataSource driver=“com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test" user=“root" password=“root"/>
  • 15. Simple Example Continued <sql:query var="employees"> SELECT * FROM employees </sql:query> <UL> <c:forEach var="row" items="${employees.rows}"> <LI><c:out value="${row.firstname}"/> <c:out value="${row.lastname}"/> </c:forEach> </UL>
  • 16. URL-Handling Tags • <c:import> - Read content from arbitrary URLs • Insert into page • Store in variable • Or make accessible via a reader - Unlike <jsp:include>, not restricted to own system • <c:redirect> - Redirects response to specified URL • <c:param> - Encodes a request parameter and adds it to a URL - May be used within body of <c:import> or <c:redirect>
  • 17. Summary • JSTL is similar to the old Struts looping and logic tags • JSTL is standardized, but not a standard part of JSP 1.2 or 2.0 - It must be downloaded and installed separately • Supports a concise expression language - Lets you access bean properties and implicit objects - EL is standard part of JSP 2.0 • Looping tags - Explicit numeric values - Arrays, collections, maps, strings, etc. • Conditional evaluation tags - Single options - Multiple options