Whenever we have 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. 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. This tag is just like the if statement in java. This tag is not for applicable if we want to one thing if the condition is true, and another thing if the condition is false. In this situation this tag will become obsolete.
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 have made a program on if statement using jstl library, in which we are going to print "Welcome to roseindia.net".
In this program we are making use of <c:if>, in which we are going to check whether the given string is equal to another string, we are not taking the case of a string into consideration. In this program we are making use of <c:set var = str value= "rOsEiNdIa"> tag. In this tag var is a must. In this tag the value is assigned to variable str. The value of the variable str cannot be accessed outside the tag, so assign the variable str to the id of useBean <jsp:useBean id="str" type="java.lang.String" />. At last from this id to check the condition whether the given string is equal to the another string or not. The test attribute of the <c: if> tag checks the condition.
The code of the program is given below:
|<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<c:set var="str" value="rOsEiNdIa" />
<jsp:useBean id="str" type="java.lang.String" />
<c:if test='<%=str.equalsIgnoreCase("roseindia")%>'> <strong>They are
The output of the program is given below:
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.