SlideShare a Scribd company logo
3
Most read
4
Most read
9
Most read
Enterprise Java
Unit-3
JSTL
• Introduction to JSTL
• Types of JSTL Tags
• Example of JSTL
By
Prof. Sandeep Vishwakarma
JSTL (JSP Standard Tag Library)
• The JSP Standard Tag Library (JSTL)
represents a set of tags to simplify the JSP
development.
• JSP Standard Tag Library (JSTL) is a standard
library of readymade tags. The JSTL
contains several tags that can remove
scriplet code from a JSP page by providing
some ready to use, already implemented
common functionalities.
Advantage of JSTL
• Fast Development JSTL provides
many tags that simplify the JSP.
• Code Reusability We can use the
JSTL tags on various pages.
• No need to use scriptlet tag It avoids
the use of scriptlet tag.
JSTL Core Tags
The JSTL core tag provides variable support, URL
management, flow control etc. The syntax used for
including JSTL core library in your JSP is:
<%@ taglib uri="http://java.sun.com/jsp/jstl/
core" prefix="c" %>
Tags Description
c:out It display the result of an expression, similar to the
way <%=...%> tag work.
c:import It Retrives relative or an absolute URL and display
the contents to either a String in 'var‘.
c:set It sets the result of an expression under evaluation in
a 'scope' variable.
c:remove It is used for removing the specified scoped variable
from a particular scope.
c:catch It is used for Catches any Throwable exceptions that
occurs in the body.
c:if It is conditional tag used for testing the condition.
c:param It adds a parameter in a containing 'import' tag's
URL.
JSTL Function Tags
The JSTL function provides a number of standard
functions, most of these functions are common
string manipulation functions. The syntax used for
including JSTL function library in your JSP is:
<%@ taglib uri="http://java.sun.com/jsp/jstl/
functions" prefix="fn" %>
JSTL Functions Description
fn:contains() It is used to test if an input string containing the
specified substring in a program.
fn:endsWith() It is used to test if an input string ends with the
specified suffix.
fn:indexOf() It returns an index within a string of first
occurrence of a specified substring.
fn:trim() It removes the blank spaces from both the ends
of a string.
fn:startsWith() It is used for checking whether the given string is
started with a particular string value.
fn:toLowerCase() It converts all the characters of a string to lower
case.
fn:toUpperCase() It converts all the characters of a string to upper
case.
fn:substring() It returns the subset of a string according to the
given start and end position.
JSTL Formatting tags
The formatting tags provide support for message
formatting, number and date formatting etc. The url
for the formatting tags is:
http://java.sun.com/jsp/jstl/fmt and prefix is fmt.
The JSTL formatting tags are used for
internationalized web sites to display and format
text, the time, the date and numbers. The syntax
used for including JSTL formatting library in your JSP
is:
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" p
refix="fmt" %>
Formatting Tags Descriptions
fmt:parseNumber It is used to Parses the string representation of
a currency, percentage or number.
fmt:timeZone It specifies a parsing action nested in its body
or the time zone for any time formatting.
fmt:formatNumber It is used to format the numerical value with
specific format or precision.
fmt:parseDate It parses the string representation of a time &
date.
fmt:setTimeZone It stores the time zone inside a time zone
configuration variable.
fmt:message It display an internationalized message.
fmt:formatDate It formats the time and/or date using the
supplied pattern and styles.
JSTL XML tags
The JSTL XML tags are used for providing a JSP-
centric way of manipulating and creating XML
documents.
The xml tags provide flow control, transformation
etc. The url for the xml tags
is http://java.sun.com/jsp/jstl/xml and prefix is x.
The JSTL XML tag library has custom tags used for
interacting with XML data. The syntax used for
including JSTL XML tags library in your JSP is:
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml"
prefix="x" %>
JSTL XML tags List
XML Tags Descriptions
x:out Similar to <%= ... > tag, but for XPath
expressions.
x:parse It is used for parse the XML data specified either
in the tag body or an attribute.
x:set It is used to sets a variable to the value of an
XPath expression.
x:when It is a subtag of that will include its body if the
condition evaluated be 'true'.
x:if It is used for evaluating the test XPath expression
and if it is true, it will processes its body content.
x:param It is used along with the transform tag for setting
the parameter in the XSLT style sheet.
JSTL SQL Tags
The JSTL sql tags provide SQL support. url of Sql tag is
http://java.sun.com/jsp/jstl/sql and prefix is sql.
The SQL tag library allows the tag to interact with RDBMSs
(Relational Databases) such as Microsoft SQL Server,
mySQL, or Oracle. The syntax used for including JSTL SQL
tags library in your JSP is:
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix=
"sql" %>
SQL Tags Descriptions
sql:setDataSource It is used for creating a simple data source
suitable only for prototyping.
sql:query It is used for executing the SQL query defined
in its sql attribute or the body.
sql:update It is used for executing the SQL update
defined in its sql attribute or in the tag body.
sql:param It is used for sets the parameter in an SQL
statement to the specified value.
sql:dateParam It is used for sets the parameter in an SQL
statement to a specified java.util.Date value.
sql:transaction It is used to provide the nested database action
with a common connection.
JSTL SQL <sql:setDataSource> Tag
The <sql:setDataSource> tag is used for
creating a simple data source suitable only for
prototyping.It is used to create the data
source variable directly from JSP and it is
stored inside a scoped variable. It can be used
as input for other database actions.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<html>
<head>
<title>sql:setDataSource Tag</title>
</head>
<body>
<sql:setDataSource var="db" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/test"
user="root" password=“cbs"/>
</body>
</html>
JSTL SQL <sql:query> Tag
The <sql:query> tag is used for executing the SQL
query defined in its sql attribute or the body. It is
used to execute an SQL SELECT statement and
saves the result in scoped variable.
Example:
<sql:query dataSource="${db}" var="rs">
SELECT * from Students;
</sql:query>
JSTL SQL <sql:query> Complete Example
• We are using the JDBC MySQL driver
• We are using the user database on local
machine
• We are using the "root" as username
and “cbs" as password to access the test
database.
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<html>
<head>
<title>sql:query Tag</title>
</head>
<body>
<sql:setDataSource var="db" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/test"
user="root" password="1234"/>
<sql:query dataSource="${db}" var="rs">
SELECT * from Students;
</sql:query>
<table border="2" width="100%">
<tr>
<th>Student ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
</tr>
<c:forEach var="table" items="${rs.rows}">
<tr>
<td><c:out value="${table.id}"/></td>
<td><c:out value="${table.First_Name}"/></td>
<td><c:out value="${table.Last_Name}"/></td>
<td><c:out value="${table.Age}"/></td>
</tr>
</c:forEach>
</table>
</body>
</html>
Thank You

More Related Content

PPTX
Enterprise java unit-1_chapter-3
PPT
Java Persistence API (JPA) Step By Step
PPTX
Enterprise java unit-2_chapter-1
PPTX
Java Server Pages(jsp)
PPTX
Introduction to Spring Boot
PDF
Enterprise java unit-3_chapter-1-jsp
PPTX
Enterprise java unit-2_chapter-2
PDF
Hibernate Presentation
Enterprise java unit-1_chapter-3
Java Persistence API (JPA) Step By Step
Enterprise java unit-2_chapter-1
Java Server Pages(jsp)
Introduction to Spring Boot
Enterprise java unit-3_chapter-1-jsp
Enterprise java unit-2_chapter-2
Hibernate Presentation

What's hot (20)

PPTX
Enterprise java unit-1_chapter-2
PPTX
Introduction to Spring Framework
PDF
Enterprise java unit-1_chapter-1
PPTX
ASP.NET MVC.
 
PPT
Hibernate architecture
PPTX
Enterprise java unit-2_chapter-3
PPTX
Spring Boot
PPT
Java Server Faces (JSF) - Basics
PPTX
Java Server Pages
PPTX
Implicit object.pptx
PDF
Learn Java with Dr. Rifat Shahriyar
PPTX
java Servlet technology
PPTX
Java Spring Framework
PPSX
Java annotations
PDF
Spring Boot
PPTX
JSP- JAVA SERVER PAGES
PDF
Introduction to java (revised)
PDF
Javascript basics
PPT
JavaScript Basics
PPTX
Spring mvc
Enterprise java unit-1_chapter-2
Introduction to Spring Framework
Enterprise java unit-1_chapter-1
ASP.NET MVC.
 
Hibernate architecture
Enterprise java unit-2_chapter-3
Spring Boot
Java Server Faces (JSF) - Basics
Java Server Pages
Implicit object.pptx
Learn Java with Dr. Rifat Shahriyar
java Servlet technology
Java Spring Framework
Java annotations
Spring Boot
JSP- JAVA SERVER PAGES
Introduction to java (revised)
Javascript basics
JavaScript Basics
Spring mvc
Ad

Similar to Jsp tag library (20)

PPTX
JSP Standard Tag Library
PPTX
jstl ( jsp standard tag library )
PDF
Jsp standard tag_library
PDF
Session_15_JSTL.pdf
PPTX
Jsp session 9
PPTX
Introduction to JSP
PPTX
JSTL.pptx
PPTX
Jsp session 13
PPTX
Jsp , javasportal, jsp basic,
PPT
Jstl &amp; El
PPTX
Implementing jsp tag extensions
PPTX
Implementing java server pages standard tag library v2
PPTX
Introduction to JSP.pptx
PPTX
PDF
Bt0083 server side programing 2
PPTX
Jsp and jstl
PPTX
Introduction - Java Server Programming (JSP)
PPS
Jsp element
PPTX
EXPRESSIONS IN JSP and Expression language in JSP
PPTX
Xml session
JSP Standard Tag Library
jstl ( jsp standard tag library )
Jsp standard tag_library
Session_15_JSTL.pdf
Jsp session 9
Introduction to JSP
JSTL.pptx
Jsp session 13
Jsp , javasportal, jsp basic,
Jstl &amp; El
Implementing jsp tag extensions
Implementing java server pages standard tag library v2
Introduction to JSP.pptx
Bt0083 server side programing 2
Jsp and jstl
Introduction - Java Server Programming (JSP)
Jsp element
EXPRESSIONS IN JSP and Expression language in JSP
Xml session
Ad

More from sandeep54552 (20)

PPTX
Dijkstra Searching Algorithms Shortest.pptx
PPTX
E_R-Diagram (2).pptx
PPTX
Dijkstra Searching Algorithms.pptx
PPTX
DFS_New.pptx
PPT
Agents_AI.ppt
PPT
YCMOU_FYBCA_DS_Unit-7.ppt
PPTX
Queue_Data_Structure.pptx
PPTX
Tree_Definition.pptx
PPTX
Stack_Application_Infix_Prefix.pptx
PPTX
Stack_Data_Structure.pptx
PPTX
Heap_Sort1.pptx
PPTX
Quick_sort1.pptx
PPTX
Link_List.pptx
PPTX
Templates in c++
PPTX
File handling in c++
PPTX
Exception handling in c++
PPTX
Inheritance in c++
PPTX
Constructor and Destructors in C++
PPTX
C++ programming introduction
PDF
Hill climbing algorithm in artificial intelligence
Dijkstra Searching Algorithms Shortest.pptx
E_R-Diagram (2).pptx
Dijkstra Searching Algorithms.pptx
DFS_New.pptx
Agents_AI.ppt
YCMOU_FYBCA_DS_Unit-7.ppt
Queue_Data_Structure.pptx
Tree_Definition.pptx
Stack_Application_Infix_Prefix.pptx
Stack_Data_Structure.pptx
Heap_Sort1.pptx
Quick_sort1.pptx
Link_List.pptx
Templates in c++
File handling in c++
Exception handling in c++
Inheritance in c++
Constructor and Destructors in C++
C++ programming introduction
Hill climbing algorithm in artificial intelligence

Recently uploaded (20)

PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
History, Philosophy and sociology of education (1).pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Empowerment Technology for Senior High School Guide
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
Lesson notes of climatology university.
PDF
1_English_Language_Set_2.pdf probationary
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
Final Presentation General Medicine 03-08-2024.pptx
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
202450812 BayCHI UCSC-SV 20250812 v17.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
History, Philosophy and sociology of education (1).pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Empowerment Technology for Senior High School Guide
Chinmaya Tiranga quiz Grand Finale.pdf
Orientation - ARALprogram of Deped to the Parents.pptx
Lesson notes of climatology university.
1_English_Language_Set_2.pdf probationary
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Weekly quiz Compilation Jan -July 25.pdf
Computing-Curriculum for Schools in Ghana
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
LDMMIA Reiki Yoga Finals Review Spring Summer

Jsp tag library

  • 1. Enterprise Java Unit-3 JSTL • Introduction to JSTL • Types of JSTL Tags • Example of JSTL By Prof. Sandeep Vishwakarma
  • 2. JSTL (JSP Standard Tag Library) • The JSP Standard Tag Library (JSTL) represents a set of tags to simplify the JSP development. • JSP Standard Tag Library (JSTL) is a standard library of readymade tags. The JSTL contains several tags that can remove scriplet code from a JSP page by providing some ready to use, already implemented common functionalities.
  • 3. Advantage of JSTL • Fast Development JSTL provides many tags that simplify the JSP. • Code Reusability We can use the JSTL tags on various pages. • No need to use scriptlet tag It avoids the use of scriptlet tag.
  • 4. JSTL Core Tags The JSTL core tag provides variable support, URL management, flow control etc. The syntax used for including JSTL core library in your JSP is: <%@ taglib uri="http://java.sun.com/jsp/jstl/ core" prefix="c" %>
  • 5. Tags Description c:out It display the result of an expression, similar to the way <%=...%> tag work. c:import It Retrives relative or an absolute URL and display the contents to either a String in 'var‘. c:set It sets the result of an expression under evaluation in a 'scope' variable. c:remove It is used for removing the specified scoped variable from a particular scope. c:catch It is used for Catches any Throwable exceptions that occurs in the body. c:if It is conditional tag used for testing the condition. c:param It adds a parameter in a containing 'import' tag's URL.
  • 6. JSTL Function Tags The JSTL function provides a number of standard functions, most of these functions are common string manipulation functions. The syntax used for including JSTL function library in your JSP is: <%@ taglib uri="http://java.sun.com/jsp/jstl/ functions" prefix="fn" %>
  • 7. JSTL Functions Description fn:contains() It is used to test if an input string containing the specified substring in a program. fn:endsWith() It is used to test if an input string ends with the specified suffix. fn:indexOf() It returns an index within a string of first occurrence of a specified substring. fn:trim() It removes the blank spaces from both the ends of a string. fn:startsWith() It is used for checking whether the given string is started with a particular string value. fn:toLowerCase() It converts all the characters of a string to lower case. fn:toUpperCase() It converts all the characters of a string to upper case. fn:substring() It returns the subset of a string according to the given start and end position.
  • 8. JSTL Formatting tags The formatting tags provide support for message formatting, number and date formatting etc. The url for the formatting tags is: http://java.sun.com/jsp/jstl/fmt and prefix is fmt. The JSTL formatting tags are used for internationalized web sites to display and format text, the time, the date and numbers. The syntax used for including JSTL formatting library in your JSP is: <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" p refix="fmt" %>
  • 9. Formatting Tags Descriptions fmt:parseNumber It is used to Parses the string representation of a currency, percentage or number. fmt:timeZone It specifies a parsing action nested in its body or the time zone for any time formatting. fmt:formatNumber It is used to format the numerical value with specific format or precision. fmt:parseDate It parses the string representation of a time & date. fmt:setTimeZone It stores the time zone inside a time zone configuration variable. fmt:message It display an internationalized message. fmt:formatDate It formats the time and/or date using the supplied pattern and styles.
  • 10. JSTL XML tags The JSTL XML tags are used for providing a JSP- centric way of manipulating and creating XML documents. The xml tags provide flow control, transformation etc. The url for the xml tags is http://java.sun.com/jsp/jstl/xml and prefix is x. The JSTL XML tag library has custom tags used for interacting with XML data. The syntax used for including JSTL XML tags library in your JSP is: <%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
  • 11. JSTL XML tags List XML Tags Descriptions x:out Similar to <%= ... > tag, but for XPath expressions. x:parse It is used for parse the XML data specified either in the tag body or an attribute. x:set It is used to sets a variable to the value of an XPath expression. x:when It is a subtag of that will include its body if the condition evaluated be 'true'. x:if It is used for evaluating the test XPath expression and if it is true, it will processes its body content. x:param It is used along with the transform tag for setting the parameter in the XSLT style sheet.
  • 12. JSTL SQL Tags The JSTL sql tags provide SQL support. url of Sql tag is http://java.sun.com/jsp/jstl/sql and prefix is sql. The SQL tag library allows the tag to interact with RDBMSs (Relational Databases) such as Microsoft SQL Server, mySQL, or Oracle. The syntax used for including JSTL SQL tags library in your JSP is: <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix= "sql" %>
  • 13. SQL Tags Descriptions sql:setDataSource It is used for creating a simple data source suitable only for prototyping. sql:query It is used for executing the SQL query defined in its sql attribute or the body. sql:update It is used for executing the SQL update defined in its sql attribute or in the tag body. sql:param It is used for sets the parameter in an SQL statement to the specified value. sql:dateParam It is used for sets the parameter in an SQL statement to a specified java.util.Date value. sql:transaction It is used to provide the nested database action with a common connection.
  • 14. JSTL SQL <sql:setDataSource> Tag The <sql:setDataSource> tag is used for creating a simple data source suitable only for prototyping.It is used to create the data source variable directly from JSP and it is stored inside a scoped variable. It can be used as input for other database actions.
  • 15. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> <html> <head> <title>sql:setDataSource Tag</title> </head> <body> <sql:setDataSource var="db" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/test" user="root" password=“cbs"/> </body> </html>
  • 16. JSTL SQL <sql:query> Tag The <sql:query> tag is used for executing the SQL query defined in its sql attribute or the body. It is used to execute an SQL SELECT statement and saves the result in scoped variable. Example: <sql:query dataSource="${db}" var="rs"> SELECT * from Students; </sql:query>
  • 17. JSTL SQL <sql:query> Complete Example • We are using the JDBC MySQL driver • We are using the user database on local machine • We are using the "root" as username and “cbs" as password to access the test database.
  • 18. <%@ page import="java.io.*,java.util.*,java.sql.*"%> <%@ page import="javax.servlet.http.*,javax.servlet.*" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> <html> <head> <title>sql:query Tag</title> </head> <body> <sql:setDataSource var="db" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/test" user="root" password="1234"/> <sql:query dataSource="${db}" var="rs"> SELECT * from Students; </sql:query>
  • 19. <table border="2" width="100%"> <tr> <th>Student ID</th> <th>First Name</th> <th>Last Name</th> <th>Age</th> </tr> <c:forEach var="table" items="${rs.rows}"> <tr> <td><c:out value="${table.id}"/></td> <td><c:out value="${table.First_Name}"/></td> <td><c:out value="${table.Last_Name}"/></td> <td><c:out value="${table.Age}"/></td> </tr> </c:forEach> </table> </body> </html>