if tag in JSP Core Tag Library
How is if tag of JSP Core Tag Library used?
Explanation
The
if tags is used to execute a set of code based on the value of its attribute "test".
Syntax:
<c:if test="booleanexpression"
var="var" [scope="page|request|session|application"]/>
In the above syntax the "var" attribute stores the instance of the value of the "test" attribute. The "scope" attribute refers the scope of variable "var". Example :
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<form>
<h5>if tag in Core tag library</h5>
Username:<input type="text" name="user" size="25">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
<br><br>
<c:if test="${param.user==''}">
Enter a valid Username
</c:if>
In the above example using the "if" tag we get the value entered in the username field using "param.user", if its empty it displays the message "Enter a valid Username".