Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Jsp JSP JSTL c:if tag

Related Tutorials


Share on Google+Share on Google+

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="" 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:


If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 4, 2009

Related Tutorials

Discuss: JSP JSTL c:if tag  

Post your Comment

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