Home Tutorial Java Jsp Jstl c:if tag in jsp

 
 

Share on Google+Share on Google+
Jstl c:if tag in jsp
Posted on: June 30, 2010 at 12:00 AM
Advertisement
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 :

After guessing correct , the output should be like this :

Download Source Code

Advertisement

Related Tags for Jstl c:if tag in jsp :


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: June 30, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com