Sunday, 2 November 2014

JAVA : JSTL core c:if Tag Example

Standard

It is just like a  if condition in Java, So, <c:if> tag is used as a conditional statement in or Jsp pages
This tag contains attributes test,var,scope. Here test is a mandatory one and var,scope's are optional 
one , we specify the evaluated condition to test attribute ,the type of the test attribute is boolean , If the condition is true then the statements will be executed with in the <c:if> and </c:if> tags. Lets' go for example program



Example :



  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"  
  2.     pageEncoding="ISO-8859-1"%>  
  3.      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  5. <html>  
  6. <head>  
  7. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">  
  8. <title>Insert title here</title>  
  9. </head>  
  10. <body>  
  11. <c:set var="money" scope="session" value="${10000}"/>   
  12.  <c:if test="${money> 0}">   
  13.          <c:out value="${money}"></c:out>  
  14.      </c:if>   
  15. </body>  
  16. </html>  

Save the above code with Extension dot JSP(.jsp) 

0 comments:

Post a Comment