By: Grenfel in JSP Tutorials on 2007年09月23日 [フレーム]
A useful feature of the EL is the ability to perform comparisons, either between numbers or objects. This feature is used primarily for the values of custom tag attributes, but can equally be used to write out the result of a comparison (true or false) to the JSP page. The EL provides the following comparison operators:
== or eq != or ne < or lt > or gt <= or le >= or ge
The second version of each operator exists to avoid having to use entity references in JSP XML syntax; however, the behavior of the operators is the same. In the JSP page in Listing below, you can see the comparison operators in use.
conditions.jsp
<html>
<head>
<title>EL Conditions</title>
<style>
body, td {font-family:verdana;font-size:10pt;}
</style>
</head>
<body>
<h2>EL Conditions</h2>
<table border="1">
<tr>
<td><b>Concept</b></td>
<td><b>EL Condition</b></td>
<td><b>Result</b></td>
</tr>
<tr>
<td>Numeric less than</td>
<td>${'${'}1 < 2}</td>
<td>${1 < 2}</td>
</tr>
<tr>
<td>Numeric greater than</td>
<td>${'${'}1 > 2}</td>
<td>${1 > 2}</td>
</tr>
<tr>
<td>Numeric less than</td>
<td>${'${'}1 lt 2}</td>
<td>${1 lt 2}</td>
</tr>
<tr>
<td>Numeric greater than</td>
<td>${'${'}1 gt 2}</td>
<td>${1 gt 2}</td>
</tr>
<tr>
<td>Numeric Greater than or equal</td>
<td>${'${'}1 >= 1}</td>
<td>${1 >= 1}</td>
</tr>
<tr>
<td>Numeric Less than or equal</td>
<td>${'${'}1 <= 1}</td>
<td>${1 <= 1}</td>
</tr>
<tr>
<td>Numeric less than or equal</td>
<td>${'${'}1 le 1}</td>
<td>${1 le 1}</td>
</tr>
<tr>
<td>Numeric greater than or equal</td>
<td>${'${'}1 ge 1}</td>
<td>${1 ge 1}</td>
</tr>
<tr>
<td>Numeric equal to</td>
<td>${'${'}1 == 1}</td>
<td>${1 == 1}</td>
</tr>
<tr>
<td>Numeric equal to</td>
<td>${'${'}1 eq 1}</td>
<td>${1 eq 1}</td>
</tr>
<tr>
<td>Numeric not equal to</td>
<td>${'${'}1 != 2}</td>
<td>${1 != 2}</td>
</tr>
<tr>
<td>Numeric not equal to</td>
<td>${'${'}1 ne 2}</td>
<td>${1 ne 2}</td>
</tr>
<tr>
<td>Alphabetic less than</td>
<td>${'${'}'abe' < 'ade'}</td>
<td>${'abe' < 'ade'}</td>
</tr>
<tr>
<td>Alphabetic greater than</td>
<td>${'${'}'abe' > 'ade'}</td>
<td>${'abe' > 'ade'}</td>
</tr>
<tr>
<td>Alphabetic equal to</td>
<td>${'${'}'abe' eq 'abe'}</td>
<td>${'abe' eq 'abe'}</td>
</tr>
<tr>
<td>Alphabetic not equal to</td>
<td>${'${'}'abe' ne 'ade'}</td>
<td>${'abe' ne 'ade'}</td>
</tr>
</table>
</body>
</html>
Again, you'll deploy the JSP page into a JSP 2.0 or JSP 2.1 compliant web container. Here is the list of steps to create, deploy, and run the JSP page:
Figure shows the web page generated by this JSP page.
Conditional operators can be used to compare operators in a JSP page. Again, parentheses can be used to alter the order of evaluation, and identical precedence operators are evaluated from left to right as follows:
() - (unary) * / div mod % + - (binary) < > <= >= lt gt le ge == != eq ne
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in JSP )
Show a calendar for user input in JSP
Encrypting Passwords in Tomcat using Servlets
JSP Tags for SQL to connect to a database
Steps to get a Free SSL certificate for your Tomcat
Uploading a file to a server using JSP
Server Side Programming using JSP
Latest Articles (in JSP)
Show a calendar for user input in JSP
Steps to get a Free SSL certificate for your Tomcat
Encrypting Passwords in Tomcat using Servlets
JSP Tags for SQL to connect to a database
Uploading a file to a server using JSP
Uploading an Image to a Database using JSP
A JSP page that gets properties from a bean
Scriptlets and Expressions in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Show a calendar for user input in JSP
Encrypting Passwords in Tomcat using Servlets
Steps to get a Free SSL certificate for your Tomcat
JSP Tags for SQL to connect to a database
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate