Jsp 在jstl if语句中使用变量

Jsp 在jstl if语句中使用变量,jsp,jstl,el,Jsp,Jstl,El,我有类似的东西 <c:forEach var="authority" items="#{SPRING_SECURITY_CONTEXT.authentication.principal.authorities}"> <c:if test="${fn:contains( ${authority} , ROLE_ADMIN) }"> </c:if> </c:forEach> 但它不工作,任何ide我如何才能做到这一点

我有类似的东西

 <c:forEach var="authority" items="#{SPRING_SECURITY_CONTEXT.authentication.principal.authorities}">

      <c:if test="${fn:contains( ${authority} , ROLE_ADMIN) }">

      </c:if>
</c:forEach>

但它不工作,任何ide我如何才能做到这一点?也许还有别的办法

//在if测试中编辑了

您缺少一个结束“)”:

 <c:forEach var="authority" items="#{SPRING_SECURITY_CONTEXT.authentication.principal.authorities}">

      <c:if test="${fn:contains( {$authority} , ROLE_ADMIN ) }">

      </c:if>
</c:forEach>

您在if测试中缺少一个“结束”):

 <c:forEach var="authority" items="#{SPRING_SECURITY_CONTEXT.authentication.principal.authorities}">

      <c:if test="${fn:contains( {$authority} , ROLE_ADMIN ) }">

      </c:if>
</c:forEach>

有两个问题:

  • 你不应该嵌套EL表达式。只需以通常的方式引用EL变量

    <c:if test="${fn:contains(authority, ROLE_ADMIN)}">
    
  • 有两个问题:

  • 你不应该嵌套EL表达式。只需以通常的方式引用EL变量

    <c:if test="${fn:contains(authority, ROLE_ADMIN)}">
    

  • 这不是问题,只是打错了。这不是问题,只是打错了