Home Jsp Simple-jsp-example with No Body
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

with No Body

Advertisement
Whenever we want to check that the value entered by the user is fulfilling the condition or not, then in these condition the tag is used.

<c:If> with No Body

        

Whenever we want to check that the value entered by the user is fulfilling the condition or not, then in these condition the <c:if> tag is used. The problem with <c:if> is that, this tag will not work if the value entered by the user doesn't match any of the condition given in the program. In this tag there is no way to specify the default value. The <c:if> tag is not for applicable if we want to do one thing if the condition is true, and another thing if the condition is false. In this situation this tag will become obsolete.  Here comes the use of  the <c:choose> tag. We are using the <c: if> having no body. 

To make a program on this, it is important to use the following tld's in the lib folder. i.e. /WEB-INF/lib folder, first is jstl.jar and the second one is standard.jar. We are making one program on <c:if > having no body.  This tag is going to check whether the condition is true or not. 

The code of the program is given below:

 

 

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<html>
<head>
<title>If with no body</title>
</head>
<body>
<form method="get">Guess I am thinking of what number?
<input type="text" name="guessGame" />
<input type="submit" value="GuessIt!" />
</form>
<c:if test="${pageContext.request.method=='GET'}">
<c:if test="${param.guessGame=='10'}" var="guessed" />

I want to check the whether you can guess my number or not. You guessed and the number you guessed is
<c:out value="${guessed}" />
</c:if> 
</body>
</html>

The output of the program is given below:

Download this example.

 

Advertisements

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: June 8, 2009

Related Tutorials

Ask Questions?    Discuss: with No Body  

Post your Comment


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