简体   繁体   中英

How do I perform bitwise logic within JSTL if statements?

I have a need to perform a bitwise test within a JSP but can't for the life of me figure out how to do it with EL.

I want to do something like:

<c:if test="${(test & testFor) == testFor}">
  <h3>Test Passed</h3>
</c:if>

Of course I can do it with ordinary JSP syntax:

<% if ((test & testFor) == testFor) { %>
  <h3>Test Passed</h3>
<% } %>

I think bitwise operators are not implemented in JSTL ( see here )

You can implement a JSTL function, called bitwiseAnd(int, int) and perform the bitwise test in Java code

JSP EL doesn't support bitwise operators (only arithmetic, logical and relational operators). If you want to do that, you'll need to encapsulate the operations within a java class, and expose that to the JSP. Alternatively, I believe you can write a custom function, that would look similar to those in the fn: JSTL namespace, but I'm not sure how to go about that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM