These tags are used as conditional statements in Jsp's. These.These tags are works like Switch case statements in Java. These tags are helpful to choose multiple options based on the conditions. <c:choose> tag works like switch and<c:when> tag works like case statement, <c:otherwise> tag works like default , it executes if none of the conditions are true. Let's go for example for better understanding purpose.
Example :
- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
- <!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="money" scope="session" value="${550}"/>
- <p>The amount is : <c:out value="${money}"/></p>
- <c:choose>
- <c:when test="${money <= 0}">
- We cannot By things
- </c:when>
- <c:when test="${money > 500}">
- Enough to Buy
- </c:when>
- <c:otherwise>
- Nothing is happen
- </c:otherwise>
- </c:choose>
- </body>
- </html>
Write the above code in Notepad++ or Notepad and save file with extension dot JSP(.jsp).
OUTPUT :


0 comments:
Post a Comment