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

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: