Jstl c:if tag in jsp


 

Jstl c:if tag in jsp

In this Section, we will discuss about how to use JSTL tag ' c:if ' in JSP with a simple example.

In this Section, we will discuss about how to use JSTL tag ' c:if ' in JSP with a simple example.

JSTL c:if TAG IN JSP

In this Section, we will discuss about how to use JSTL tag ' c:if ' in JSP with a simple example.

The "c:if" tag of JSTL is very similar to "if" control statement of java. It also checks the condition and if condition is true...it will execute the statement in the block. If condition is not true it will skip the block and execute the next statements.

Syntax: <c:if test="${  condition }>  BLOCK  </c:if>

for example : <c:if test="${param.guess=='roseindia'}"> You have guessed the word.</c:if>

The "test" attribute of JSTL "c:if" tag ,have the condition block.

EXAMPLE :

In the below example, user have to guess the 'company name' , if the guessed name is correct or incorrect , it will display a message according to the condition.

CifJSTL.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>

<body>

<form method="post">

<center><b><font color="blue">WELCOME TO ROSEINDIA TECHNOLOGIES

</font></b></center>

<br><br><center>Guess the Company Name

<input type="text" name="guess" />

<input type="submit" value="Guess!" /></center>

<c:if test="${pageContext.request.method=='POST'}">

<center>

<c:if test="${param.guess=='roseindia'}">BINGO ! You are Right.

</c:if></center>

<center>

<c:if test="${param.guess!='roseindia'}">TRY AGAIN! You are wrong.

</c:if></center>

</c:if>

</form>

</body>

</html>

OUTPUT :

0

After guessing correct , the output should be like this :

Download Source Code

1

Ads