This tag is to use to define the Control statements In JSP. Like to choose or select from conditional Criteria…!

                                                 Voter.xml” (XML File for Program)

<?xml version="1.0" ?>

<voter>

<vote>

<name>Dev</name>

<age>18</age>

</vote>

<vote>

<name>Ashu</name>

<age>20</age>

</vote>

</voter>

                                                                 If.jsp            

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>

<html>

     <head>

           <title>&lt;x:if&gt;Tag In JSTL</title>

     </head>

       <body>

             <center><b><h3>Voting Eligibility</h3>

             <c:import url="voter.xml" var="vtr"/>

             <x:parse xml="${vtr}" var="disp"/>

             <x:if select="$disp//vote">

                  <p><center><b>Only One Can vote </b></center></p>

             </x:if> <br />

             <x:if select="$disp/voter[1]/vote/age <= 18">

                     <center><b><p>You can Vote...</p></b></center>

             </x:if>

        </body>

</html>

        JSTL XML <x:if> Tag

In This Program We Create a XML File as per Mention above named ‘Voter.xml’. That will be accessed while compiling the Program. Required attributes are also declared with the mandatory Variable. The Body section contains the main part of structure like Import URL will import the contents from XML file on The Web page. The Condition will be checked as per either the candidate will vote or not. In the Last all the tags will be closed.





About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.