SlideShare a Scribd company logo
1 of 17
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

What's hot

Running ms sql stored procedures in mule
Running ms sql stored procedures in muleRunning ms sql stored procedures in mule
Running ms sql stored procedures in muleAnilKumar Etagowni
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programmingchhaichivon
 
Persitance Data with sqlite
Persitance Data with sqlitePersitance Data with sqlite
Persitance Data with sqliteArif Huda
 
Apache Con Us2007 Apachei Batis
Apache Con Us2007 Apachei BatisApache Con Us2007 Apachei Batis
Apache Con Us2007 Apachei Batisday
 
Advance java session 10
Advance java session 10Advance java session 10
Advance java session 10Smita B Kumar
 
Deploy and Manage the Infrastructure Using Azure Resource Manager
Deploy and Manage the Infrastructure Using Azure Resource ManagerDeploy and Manage the Infrastructure Using Azure Resource Manager
Deploy and Manage the Infrastructure Using Azure Resource ManagerGlobalLogic Ukraine
 
Backbonejs for beginners
Backbonejs for beginnersBackbonejs for beginners
Backbonejs for beginnersDivakar Gu
 
Persistence with Ada Database Objects (ADO)
Persistence with Ada Database Objects (ADO)Persistence with Ada Database Objects (ADO)
Persistence with Ada Database Objects (ADO)Stephane Carrez
 
Liquidating database frustrations with liquibase
Liquidating database frustrations with liquibaseLiquidating database frustrations with liquibase
Liquidating database frustrations with liquibasePaul Churchward
 
Rails application refactoring steps
Rails application refactoring stepsRails application refactoring steps
Rails application refactoring stepsMasud Rana
 

What's hot (20)

Running ms sql stored procedures in mule
Running ms sql stored procedures in muleRunning ms sql stored procedures in mule
Running ms sql stored procedures in mule
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programming
 
Persitance Data with sqlite
Persitance Data with sqlitePersitance Data with sqlite
Persitance Data with sqlite
 
JSP - Part 1
JSP - Part 1JSP - Part 1
JSP - Part 1
 
Apache Con Us2007 Apachei Batis
Apache Con Us2007 Apachei BatisApache Con Us2007 Apachei Batis
Apache Con Us2007 Apachei Batis
 
Qure Tech Presentation
Qure Tech PresentationQure Tech Presentation
Qure Tech Presentation
 
Advance java session 10
Advance java session 10Advance java session 10
Advance java session 10
 
Deploy and Manage the Infrastructure Using Azure Resource Manager
Deploy and Manage the Infrastructure Using Azure Resource ManagerDeploy and Manage the Infrastructure Using Azure Resource Manager
Deploy and Manage the Infrastructure Using Azure Resource Manager
 
Html To JSP
Html To JSPHtml To JSP
Html To JSP
 
Jdbc
JdbcJdbc
Jdbc
 
servlets and jsp
servlets and jspservlets and jsp
servlets and jsp
 
Sql lite android
Sql lite androidSql lite android
Sql lite android
 
Backbonejs for beginners
Backbonejs for beginnersBackbonejs for beginners
Backbonejs for beginners
 
Persistence with Ada Database Objects (ADO)
Persistence with Ada Database Objects (ADO)Persistence with Ada Database Objects (ADO)
Persistence with Ada Database Objects (ADO)
 
Persistences
PersistencesPersistences
Persistences
 
Java >= 9
Java >= 9Java >= 9
Java >= 9
 
Grails Controllers
Grails ControllersGrails Controllers
Grails Controllers
 
Liquidating database frustrations with liquibase
Liquidating database frustrations with liquibaseLiquidating database frustrations with liquibase
Liquidating database frustrations with liquibase
 
Rails application refactoring steps
Rails application refactoring stepsRails application refactoring steps
Rails application refactoring steps
 
XSLT presentation
XSLT presentationXSLT presentation
XSLT presentation
 

Similar to Advance java session 16

Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, mavenFahad Golra
 
Ch. 9 jsp standard tag library
Ch. 9 jsp standard tag libraryCh. 9 jsp standard tag library
Ch. 9 jsp standard tag libraryManolis Vavalis
 
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004derek_clark_ashmore
 
13 java beans
13 java beans13 java beans
13 java beanssnopteck
 
Implementing java server pages standard tag library v2
Implementing java server pages standard tag library v2Implementing java server pages standard tag library v2
Implementing java server pages standard tag library v2Soujanya V
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Ayes Chinmay
 
15 expression-language
15 expression-language15 expression-language
15 expression-languagesnopteck
 
Ajax Tags Advanced
Ajax Tags AdvancedAjax Tags Advanced
Ajax Tags AdvancedAkramWaseem
 
Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalache
Iasi code camp 12 october 2013   jax-rs-jee-ecosystem - catalin mihalacheIasi code camp 12 october 2013   jax-rs-jee-ecosystem - catalin mihalache
Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalacheCodecamp Romania
 
Struts2-Spring=Hibernate
Struts2-Spring=HibernateStruts2-Spring=Hibernate
Struts2-Spring=HibernateJay Shah
 

Similar to Advance java session 16 (20)

Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, maven
 
10 jdbc
10 jdbc10 jdbc
10 jdbc
 
Ch. 9 jsp standard tag library
Ch. 9 jsp standard tag libraryCh. 9 jsp standard tag library
Ch. 9 jsp standard tag library
 
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
Jdbc Best Practices - DB2/ IDUG - Orlando, May 10, 2004
 
13 java beans
13 java beans13 java beans
13 java beans
 
Jsp
JspJsp
Jsp
 
Implementing java server pages standard tag library v2
Implementing java server pages standard tag library v2Implementing java server pages standard tag library v2
Implementing java server pages standard tag library v2
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
 
15 expression-language
15 expression-language15 expression-language
15 expression-language
 
Java .ppt
Java .pptJava .ppt
Java .ppt
 
25.ppt
25.ppt25.ppt
25.ppt
 
Jstl
JstlJstl
Jstl
 
Ajax Tags Advanced
Ajax Tags AdvancedAjax Tags Advanced
Ajax Tags Advanced
 
JSTL.pptx
JSTL.pptxJSTL.pptx
JSTL.pptx
 
14 mvc
14 mvc14 mvc
14 mvc
 
JSP Part 2
JSP Part 2JSP Part 2
JSP Part 2
 
Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalache
Iasi code camp 12 october 2013   jax-rs-jee-ecosystem - catalin mihalacheIasi code camp 12 october 2013   jax-rs-jee-ecosystem - catalin mihalache
Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalache
 
Struts2-Spring=Hibernate
Struts2-Spring=HibernateStruts2-Spring=Hibernate
Struts2-Spring=Hibernate
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
 
10 jsp-scripting-elements
10 jsp-scripting-elements10 jsp-scripting-elements
10 jsp-scripting-elements
 

More from Smita B Kumar

Advance java session 20
Advance java session 20Advance java session 20
Advance java session 20Smita B Kumar
 
Advance java session 19
Advance java session 19Advance java session 19
Advance java session 19Smita B Kumar
 
Advance java session 18
Advance java session 18Advance java session 18
Advance java session 18Smita B Kumar
 
Advance java session 17
Advance java session 17Advance java session 17
Advance java session 17Smita B Kumar
 
Advance java session 15
Advance java session 15Advance java session 15
Advance java session 15Smita B Kumar
 
Advance java session 14
Advance java session 14Advance java session 14
Advance java session 14Smita B Kumar
 
Advance java session 13
Advance java session 13Advance java session 13
Advance java session 13Smita B Kumar
 
Advance java session 12
Advance java session 12Advance java session 12
Advance java session 12Smita B Kumar
 
Advance java session 11
Advance java session 11Advance java session 11
Advance java session 11Smita B Kumar
 
Advance java session 9
Advance java session 9Advance java session 9
Advance java session 9Smita B Kumar
 
Advance java session 8
Advance java session 8Advance java session 8
Advance java session 8Smita B Kumar
 
Advance java session 7
Advance java session 7Advance java session 7
Advance java session 7Smita B Kumar
 
Advance java session 6
Advance java session 6Advance java session 6
Advance java session 6Smita B Kumar
 
Advance java session 5
Advance java session 5Advance java session 5
Advance java session 5Smita B Kumar
 
Advance java session 4
Advance java session 4Advance java session 4
Advance java session 4Smita B Kumar
 
Advance java session 3
Advance java session 3Advance java session 3
Advance java session 3Smita B Kumar
 
Advance java session 2
Advance java session 2Advance java session 2
Advance java session 2Smita B Kumar
 
01 introduction to struts2
01 introduction to struts201 introduction to struts2
01 introduction to struts2Smita B Kumar
 

More from Smita B Kumar (19)

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

Recently uploaded

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 

Recently uploaded (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 

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