Home Jsp JSP JSTL c:if tag
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

JSP JSTL c:if tag

Advertisement
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" %>
<html>
<body>
<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>
<c:if test="${param.guess!='roseindia'}">You are wrong!
</c:if>
</c:if>
</form>
</body>
</html>

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:

Advertisements

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

Ask Questions?    Discuss: JSP JSTL c:if tag  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com