How to make java block equivalent if-else using JSTL?

Quick JSTL Question. I usually use scripts on my jsp pages, but I have a conflict due to some other things on my page. I understand that you can do something similar using JSTL, although I am not familiar with this. Here is what I would like to use java for this:

if (var1.equalsIgnoreCase(var2)) { some html stuff } else { more html } 

So can it be converted and translated for use with JSTL?

Thanks in advance, and if you have any questions, just let me know.

+23
java jstl
Jun 02 '11 at 19:17
source share
2 answers

You can use <c:choose> . equalsIgnoreCase() can be done by decreasing both sides by fn:toLowerCase() .

 <c:choose> <c:when test="${fn:toLowerCase(var1) == fn:toLowerCase(var2)}"> Both are equal. </c:when> <c:otherwise> Both are not equal. </c:otherwise> </c:choose> 

Or, when you target a Servlet 3.0 container (Tomcat 7, Glassfish 3, JBoss AS 6, etc.) with the declared web.xml Servlet 3.0 convention, you can call the equalsIgnoreCase() method.

 <c:choose> <c:when test="${var1.equalsIgnoreCase(var2)}"> Both are equal. </c:when> <c:otherwise> Both are not equal. </c:otherwise> </c:choose> 
+56
Jun 02 '11 at 19:20
source share
 <c:if test=${var1 == var2)}> </c:if> 

No Else is JSTL, you need to do some If (Sucks I know)

Need to add this at the top

 <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> 
+2
Jun 02 '11 at 19:20
source share



All Articles