问题
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 highlight them in same color.
<c:if test="${"POST".equalsIgnoreCase(pageContext.request.method) && pageContext.request.getParameter("submit") !=null}">
</c:if>
Does that mean that EL does not recognize the string and so gives me an EL syntax error?
How can I solve this?
回答1:
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>
回答2:
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>
来源:https://stackoverflow.com/questions/51262044/jstl-cif-does-not-recognize-string-inside-and-causes-el-syntax-error