Thiago Vacare Thiago Vacare - 3 months ago 22
Java Question

JSTL - Comparing Strings

I'm trying to compare two strings but I can't get the result I need

I tried these formats:

<c:choose>
<c:when test="${company == multi }">
<a href="dashResumo.jsp?tr=<%=tr%>&company=VVO&nm=<%=nmTorr%>"></a>
<a href="dashResumo.jsp?tr=<%=tr%>&company=GPA&nm=%=nmTorr%></a>
</c:when>
</c:choose>

<c:choose>
<c:when test="${company == 'multi' }">
<a href="dashResumo.jsp?tr=<%=tr%>&company=VVO&nm=<%=nmTorr%>"></a>
<a href="dashResumo.jsp?tr=<%=tr%>&company=GPA&nm=%=nmTorr%>">GPA</a>
</c:when>
</c:choose>

<c:choose>
<c:when test="${company.equals("multi") }">
<a href="dashResumo.jsp?tr=<%=tr%>&company=VVO&nm=<%=nmTorr%></a>
<a href="dashResumo.jsp?tr=<%=tr%>&company=GPA&nm=%=nmTorr%></a>
</c:when>
</c:choose>


but none of these formats worked for me.

Using JSTL-1.2 library

Answer

Try with this:

<c:choose>
    <c:when test="${company eq 'multi'}">
        <a href="dashResumo.jsp?tr=<%=tr%>&company=VVO&nm=<%=nmTorr%>">VVO</a>
        <a href="dashResumo.jsp?tr=<%=tr%>&company=GPA&nm=<%=nmTorr%>">GPA</a>                                    
    </c:when>
</c:choose>