JSTL c:if does not recognize String inside ${} and causes EL syntax error

前端 未结 2 601
伪装坚强ぢ
伪装坚强ぢ 2020-12-12 04:11

Why are the "POST" and "submit" parts of this code highlighted in a different color in my IDE?

Also the syntax highlighter here doesn\'t h

相关标签:
2条回答
  • 2020-12-12 04:38

    Use a backslash character to escape the double quotes like this:

    <c:if test="${\"POST\".equalsIgnoreCase(pageContext.request.method)  && pageContext.request.getParameter(\"submit\") !=null}">
    </c:if>
    
    0 讨论(0)
  • 2020-12-12 04:59

    Inside the <c:if>, your test attribute is a also a string, which is set with double quotes, and you also have "POST" as string literal which you are using inside string as string with double quotes. So compiler understands that as end of <c:if test> condition. In effects, you end up having a <c:if test="${"> instead of the intended one.

    Replace the double quotes inside the test attribute with single quotes like this:

    <c:if test="${'POST'.equalsIgnoreCase(pageContext.request.method) && pageContext.request.getParameter('submit') != null}">
    
    </c:if>
    
    0 讨论(0)
提交回复
热议问题