Practical 5c
Practical 5c
1. Core tags
1. Core.jsp
Output:
2. Formatting tags
1. Formatting.jsp
<html>
<head>
<title>fmt:formatNumber Tag</title>
</head>
<body>
<h3>Formatting of Number:</h3>
<c:set var="Amount" value="9850.14115" />
<p> Formatted Number-1:
<fmt:formatNumber value="${Amount}" type="currency" /></p>
<p>Formatted Number-2:
<fmt:formatNumber type="number" groupingUsed="true" value="$
{Amount}" /></p>
<p>Formatted Number-3:
<fmt:formatNumber type="number" maxIntegerDigits="3" value="$
{Amount}" /></p>
<p>Formatted Number-4:
<fmt:formatNumber type="number" maxFractionDigits="6" value="$
{Amount}" /></p>
<p>Formatted Number-5:
<fmt:formatNumber type="percent" maxIntegerDigits="4" value="$
{Amount}" /></p>
<p>Formatted Number-6:
<fmt:formatNumber type="number" pattern="###.###$" value="$
{Amount}" /></p>
</body>
</html>
Output:
3. Function tags
1. Function.jsp
</body>
</html>
Output:
4. Xml tags
1. Xml.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"
%>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"
%>
<html>
<head>
<title>XML Tags</title>
</head>
<body>
<h2>Vegetable Information:</h2>
<c:set var="vegetable">
<vegetables>
<vegetable>
<name>onion</name>
<price>40/kg</price>
</vegetable>
<vegetable>
<name>Potato</name>
<price>30/kg</price>
</vegetable>
<vegetable>
<name>Tomato</name>
<price>90/kg</price>
</vegetable>
</vegetables>
</c:set>
<x:parse xml="${vegetable}" var="output"/>
<b>Name of the vegetable is</b>:
<x:out select="$output/vegetables/vegetable[1]/name"
/><br>
<b>Price of the Potato is</b>:
<x:out select="$output/vegetables/vegetable[2]/price" />
</body>
</html>
Output:
5. Sql tags
1. Create table Students
2. Sql.jsp
<%@ 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:update Tag</title>
</head>
<body>
<sql:setDataSource var="db" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/test" user="" password=""/>
<c:set var="StudentId" value="152"/>
<sql:update dataSource="${db}" var="count">
DELETE FROM Students WHERE Id = ?
<sql:param value="${StudentId}" />
</sql:update>
</body>
</html>
Output: