JSP JSTL c:if tag

The c:if tag is used for a decision need, to be made in the page.

JSP JSTL c:if tag


In this section, you will learn how to use jstl if tag in jsp. 

The c:if tag is used for a decision need, to be made in the page. If the result of processing the test using the EL Expression pageContext.request.method=='POST' is true, the body of the tag is processed otherwise it is skipped. In the given example, we prompt the user to guess the word. If he entered the specified word, the message 'You have guessed the word!' will be displayed otherwise the error message will displayed. 





 Here is the code of ifTag.jsp

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<form method="post">Guess the word
<input type="text" name="guess" />
<input type="submit" value="Guess!" />
<c:if test="${pageContext.request.method=='POST'}">
<c:if test="${param.guess=='roseindia'}">You have guessed the word!
<c:if test="${param.guess!='roseindia'}">You are wrong!

Output will be displayed as:

If the specified value is entered, output will be:

If the entered value is wrong, output will be:

Download Source Code:

Share on Google+Share on Google+

JSP JSTL c:if tag

Posted on: February 4, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: JSP JSTL c:if tag  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image