AJP Lab Exercise-13


 13.Write down a program which demonstrates the Format tag of JSTL.



----------------------------------------


formattag.jsp



<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>JSTL Format Tag Example</title>
</head>
<body>
    <h2>JSTL Formatting Tag Demonstration</h2>

    <!-- Format Number -->
    <p><b>Original Number:</b> 12345.6789</p>
    <p><b>Formatted Number:</b> 
        <fmt:formatNumber value="12345.6789" type="number" maxFractionDigits="2"/>
    </p>

    <!-- Format Currency -->
    <p><b>Currency Format (Default Locale):</b>
        <fmt:formatNumber value="12345.6789" type="currency"/>
    </p>

    <!-- Format Percent -->
    <p><b>Percent Format:</b>
        <fmt:formatNumber value="0.85" type="percent"/>
    </p>

    <!-- Set current date using JSTL -->
    <c:set var="now" value="<%= new java.util.Date() %>" />

    <!-- Format Date -->
    <p><b>Current Date (Default Format):</b>
        <fmt:formatDate value="${now}" type="both"/>
    </p>

    <!-- Custom Date Pattern -->
    <p><b>Custom Date Format (dd-MM-yyyy):</b>
        <fmt:formatDate value="${now}" pattern="dd-MM-yyyy"/>
    </p>
</body>
</html>


---------------------------------------