Home Jsp JSP JSTL c:if tag



JSP JSTL c:if tag
Posted on: February 4, 2009 at 12:00 AM
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:

Related Tags for JSP JSTL c:if tag:
ctextprocesspostiomethodsedrequesttestippageexpressiontagcontextusingprocessingiftexfortoexpresspossseciprocssiexteitusewiseulresultpeceinskipbodymnttrososadestrueagemeproppssueeessquestntextkisipppressprexpxtwisssrocthstprocesprono


More Tutorials from this section

Ask Questions?    Discuss: JSP JSTL c:if tag  

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.