JSTL
JSTL
<html>
<head>
<title>Core Tag Example</title>
</head>
<body>
<c:set var="Income" scope="session" value="${4000*4}"/>
<c:out value="${Income}"/>
</body>
</html>
SCOPE
PAGE- For the current page
REQUEST- For the current Request
SESSION- For the current Session
APPLICATION- Accessible everywhere
c:remove
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Core Tag Example</title>
</head>
<body>
<c:set var="income" scope="session" value="${4000*4}"/>
<p>Before Remove Value is: <c:out value="${income}"/></p>
<c:remove var="income"/>
<p>After Remove Value is: <c:out value="${income}"/></p>
</body>
</html>
<c:catch> <c:if>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Core Tag Example</title>
</head>
<body>
</body>
</html>
<c:choose>, <c:when>, <c:otherwise> Tag
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Core Tag Example</title>
</head>
<body>
<c:set var="income" scope="session" value="${4000*4}"/>
<p>Your income is : <c:out value="${income}"/></p>
<c:choose>
<c:when test="${income <= 1000}">
Income is not good.
</c:when>
<c:when test="${income > 10000}">
Income is very good.
</c:when>
<c:otherwise>
Income is undetermined...
</c:otherwise>
</c:choose>
</body>
</html>
<c:forEach>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core“ prefix="c" %>
<html>
<head>
<title>Core Tag Example</title>
</head>
<body>
<c:forEach var="j" begin="1" end="3">
Item <c:out value="${j}"/><p>
</c:forEach>
</body>
</html>
• <c:param> URL request parameter to be
specified within URL and it automatically
perform any necessary URL encoding
• The < c:redirect > tag redirects the browser to
a new URL
• The < c:url > tag creates a URL
Functional tags
1. fn:contains()
2. fn:containsIgnoreCase()
3. fn:endsWith()
4. fn:escapeXml()
5. fn:indexOf()
6. fn:trim()
7. fn:startsWith()
8. fn:split()
9. fn:toLowerCase()
10. fn:toUpperCase()
11. fn:substring()
12. fn:substringAfter()
13. fn:substringBefore()
14. fn:length()
15. fn:replace()
fn:contains
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<head>
<title>Using JSTL Functions</title>
</head>
<body>
<c:set var="String" value="Welcome to cse"/>
<c:if test="${fn:contains(String, 'cse')}">
<p>Found cse string<p>
</c:if>
<c:if test="${fn:contains(String, ‘cse')}">
<p>Found cse string<p>
</c:if>
</body>
</html>
escapeXml
<c:set var="string1" value="It is first String."/>
<c:set var="string2" value="It is <xyz>second String.</xyz
>"/>
1. fmt:parseNumber
2. fmt:timeZone
3. fmt:formatNumber
4. fmt:parseDate
5. fmt:bundle
6. fmt:setTimeZone
7. fmt:setBundle
8. fmt:message
9. fmt:formatDate
fmt:parseNumber
<html>
<head>
<title>fmt:parseNumber tag</title>
</head>
<body>
<h3>The fmt:parseNumber tag Example is:</h3>
</body>
</html>
<x:if>
<c:set var="vegetables">
<vegetables>
<vegetable>
<name>onion</name>
<price>40</price>
</vegetable>
<vegetable>
<name>Potato</name>
<price>30</price>
</vegetable>
<vegetable>
<name>Tomato</name>
<price>90</price>
</vegetable>
</vegetables>
</c:set>
<x:parse xml="${vegetables}" var="output"/>
<x:if select="$output/vegetables/vegetable/price < 100">
Vegetables prices are very low.
</x:if>
</body>
</html>
• <x:transform> tag is used in a XML document
for providing the XSL (Extensible Stylesheet
Language) transformation. It is used for
transforming xml data based on XSLT script.
• The <x:param> tag is used to set the
parameter in the XSLT style sheet. It use along
with the transform tag for sending parameter
along with the value.
SQL tags
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.
sql:setDataSource
<%@ 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>
</body>
</html>
sql:transaction
<%
Date DoB = new Date("2000/10/16");
int studentId = 151;
%>
<sql:transaction dataSource="${db}">
<sql:update var="count">
UPDATE Student SET First_Name = 'Suraj' WHERE Id = 150
</sql:update>
<sql:update var="count">
UPDATE Student SET Last_Name= 'Saifi' WHERE Id = 153
</sql:update>
<sql:update var="count">
INSERT INTO Student
VALUES (154,'Supriya', 'Jaiswal', '1995/10/6');
</sql:update>
</sql:transaction>