JSTL c:if无法识别$ {}中的String并导致EL语法错误 [英] JSTL c:if does not recognize String inside ${} and causes EL syntax error

查看:84
本文介绍了JSTL c:if无法识别$ {}中的String并导致EL语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 POST是和提交

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

<c:if test="${"POST".equalsIgnoreCase(pageContext.request.method) && pageContext.request.getParameter("submit") !=null}">

</c:if>

这是否意味着EL无法识别字符串,因此给我EL语法错误?

Does that mean that EL does not recognize the string and so gives me an EL syntax error?

我该如何解决?

推荐答案

< c:if>内部,您的 test 属性也是一个字符串,该字符串用双引号设置,并且您还具有 POST ; 作为字符串文字,您正在字符串内部使用双引号作为字符串。因此,编译器理解为< c:if test> 条件的结尾。实际上,您最终得到的是< c:if test = $ {> 而不是预期的。

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.

test 属性内的双引号替换为单引号,如下所示:

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>

这篇关于JSTL c:if无法识别$ {}中的String并导致EL语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆