Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

JSP JSTL c:when tag

In this section, you will learn how to use the jstl when tag in jsp. Basically, the choose, when, and otherwise tags can be used to construct an if statement.

Ads

JSP JSTL c:when tag

        

In this section, you will learn how to use the jstl when tag in jsp. Basically, the choose, when, and otherwise tags can be used to construct an if statement. The choose tag embedded the subtag when which evaluates the test condition. If none of the test conditions of when tags evaluates to true, then the otherwise tag is evaluated. In the given example, we prompt the user to enter to enter any number. After submitting the button, a message will be displayed showing whether the number is odd or even.

 

 

 

 

Here is the code of when.jsp:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<body>
<form method="post">Enter a number:
<input type="text" name="enter" />
<input type="submit" value="Accept" />
<br />
</form>
<c:if test="${pageContext.request.method=='POST'}">Entered value is:
<c:choose>
<c:when test="${param.enter%2==0}">even.
<br />
</c:when>
<c:otherwise>odd.
<br />
</c:otherwise>
</c:choose>
</c:if>
</body>
</html>

Output will be displayed as:

If the entered number is even:

If the entered number is odd:

Download Source Code:

Advertisements

Ads
Share on Google+Share on Google+

JSP JSTL c:when tag

Posted on: February 4, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: JSP JSTL c:when tag  

Post your Comment


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

Ads

 

Ads