JSTL Tags PDF
JSTL Tags PDF
AllInOneExample: index.jsp
<%@page import="java.util.*"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<c:set var="eid" value="10" scope="request"/>
<c:choose>
<c:when test="${eid lt 0 }">
<c:out value="-ve value"/>
</c:when>
<c:when test="${eid gt 0}">
1|Page
RAGHU SIR SATHYA TECHNOLOGIES, AMEERPET
<c:remove var="eid"/>
Data is:<c:out value="${eid}"/>
<%
List<String> al=Arrays.asList("A","B","C");
request.setAttribute("list", al);
%>
<c:forEach items="${list}" var="ob">
<c:out value="${ob}"/>
</c:forEach>
<c:catch var="ae">
<%
int a=10/0;
%>
</c:catch>
<c:out value="${ae}"/>
<c:import url="hi.jsp"/>
</body>
</html>
2|Page
RAGHU SIR SATHYA TECHNOLOGIES, AMEERPET
AllInOneExample: index.jsp
<sql:setDataSource driver="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@localhost:1522:ORCL"
user="system" password="Admin" var="ds"/>
<sql:query var="rs" dataSource="${ds}" sql="select * from empstab"/>
<sql:transaction dataSource="${ds}">
<sql:update sql="insert into empstab values(22,'RR',3.3,sysdate)"/>
<sql:update sql="insert into empstab values(23,'RT',3.3,sysdate)"/>
<sql:update sql="insert into empstab values(24,'RZ',3.3,sysdate)"/>
</sql:transaction>
3|Page
RAGHU SIR SATHYA TECHNOLOGIES, AMEERPET
AllInOneExample: index.jsp
<html>
<body>
<pre>
<c:set value="Hello from Sathya Technologies" var="str"/>
STR: ${str }
SUB STR: ${fn:substring(str,2,7) }
SUB STR: ${fn:substringAfter(str,'from') }
SUB STR: ${fn:substringBefore(str,'Sathya') }
4|Page
RAGHU SIR SATHYA TECHNOLOGIES, AMEERPET
REPLACE : ${fn:replace(str3,'Hello','hi') }
AllInOneExample:index.jsp
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<body>
<pre>
<c:set var="cost" value="12255.669858"/>
<fmt:parseNumber var="i" value="${cost}" integerOnly="true"/>
Cost is: ${i}
US: <fmt:formatNumber currencyCode="USD" value="${cost}"
type="currency"/>
INDIA: <fmt:formatNumber currencyCode="INR" value="${cost}"
type="currency"/>
GROUP: <fmt:formatNumber value="${cost}" type="currency"
groupingUsed="true"/>
5|Page
RAGHU SIR SATHYA TECHNOLOGIES, AMEERPET
AllInOneExample:index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<html>
<body>
<h2>Hello</h2>
6|Page
RAGHU SIR SATHYA TECHNOLOGIES, AMEERPET
<c:set var="emps">
<employees>
<employee>
<empId>10</empId>
<empName>AJAY</empName>
<empSal>366.36</empSal>
</employee>
<employee>
<empId>11</empId>
<empName>VIJAY</empName>
<empSal>855.36</empSal>
</employee>
<employee>
<empId>12</empId>
<empName>JAI</empName>
<empSal>985.36</empSal>
</employee>
</employees>
</c:set>
<pre>
<x:parse xml="${emps}" var="data"/>
<x:set var="ename" select="$data/employees/employee[2]/empName"/>
<x:out select="$ename"/>
<x:out select="$data/employees/employee[1]/empId"/>
<x:choose>
<x:when select="$data/employees/employee[1]/empSal < 20000">
Good, But not OK
</x:when>
<x:when select="$data/employees/employee[1]/empSal > 20000">
Nice, Be happy
</x:when>
<x:otherwise>
Unable to get Data
</x:otherwise>
</x:choose>
<x:if select="$data/employees/employee[2]/empName = 'VIJAY'">
Hello VIJAY
</x:if>
</pre>
</body>
</html>
FB : https://www.facebook.com/groups/thejavatemple/
email : [email protected]
7|Page