Home Jsp JSP JSTL c:when tag
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

JSP JSTL c:when tag

Advertisement
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.

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:

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


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: February 4, 2009

Related Tutorials

Ask Questions?    Discuss: JSP JSTL c:when tag  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com