简体   繁体   English

在JSTL el表达式中转义引号时,为什么会出现JSP错误“属性未正确终止”?

[英]Why do I get the JSP error “attribute for ” is not properly terminated" when escaping quote in JSTL el expression?

I have been developing on Mac for over 8 years and I wanted to give Windows 10 another chance. 我在Mac上进行开发已有8年以上,我想再给Windows 10一个机会。 So I checked in all my projects into GitHub on the Mac and then synchronised the projects on my Windows 10 machine. 因此,我将所有项目签入Mac上的GitHub,然后在Windows 10计算机上同步了项目。

Once I ran the project in NetBeans and navigated to certain JSP pages, I received the following error... 在NetBeans中运行项目并导航到某些JSP页面后,我收到以下错误...

18-May-2018 09:46:24.335 SEVERE [http-nio-8084-exec-27] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [jsp] in context with path [/Project] threw exception [/WEB-INF/tags/config.tag (line: 46, column: 34) attribute for " is not properly terminated] with root cause org.apache.jasper.JasperException: /WEB-INF/tags/config.tag (line: 46, column: 34) attribute for " is not properly terminated 18-May-2018 09:46:24.335 SEVERE [http-nio-8084-exec-27] org.apache.catalina.core.StandardWrapperValve.invoke路径为[/ Project]的Servlet [jsp]的Servlet.service() ]引发异常[/WEB-INF/tags/config.tag(第46行,第34列)属性未正确终止]的根本原因是org.apache.jasper.JasperException:/ WEB-INF / tags / config .tag(第46行,第34列)的属性未正确终止

On the line specified I have the following... 在指定的行上,我有以下内容...

<c:when test="${storageType == \"boolean\"}">

And whilst I could change it to the following... 虽然我可以将其更改为以下内容...

<c:when test="${storageType == 'boolean'}">

I have many places in my tags and JSP where I've escaped the quotation ("), I don't see why I have to change this. My project is working in production as-is, so I don't want to unnecessarily touch JSP / tag files. 我在标签和JSP中有很多地方都没有使用引号(“),我不明白为什么必须更改它。我的项目按原样在生产中工作,所以我不想不必要地触摸JSP /标记文件。

On my Mac, which is using JDK 1.8.0_102 it works fine 在使用JDK 1.8.0_102的Mac上,它工作正常

On my Windows 10, which is using JDK 1.8.0_172 it is not working 在使用JDK 1.8.0_172的Windows 10上无法正常工作

I'm using NetBeans, with the forementioned JDKs. 我正在使用带有上述JDK的NetBeans。

Tomcat on Windows = 8.0.27.0 Windows上的Tomcat = 8.0.27.0

Tomcat on Mac = 8.0.23.0 Mac上的Tomcat = 8.0.23.0

UPDATE 更新

This works.. 这有效..

<c:if test="${key == 'testing'}">
    <div>TESTING-A</div>
</c:if>

This does NOT work... 这行不通...

<c:if test="${key == \"testing\"}">
    <div>TESTING-A</div>
</c:if>

The latter causes the error at runtime 后者在运行时导致错误

[/WEB-INF/tags/config.tag (line: 27, column: 12) attribute for " is not properly terminated] with root cause org.apache.jasper.JasperException: /WEB-INF/tags/config.tag (line: 27, column: 12) attribute for " is not properly terminated. [/WEB-INF/tags/config.tag(第27行,第12列)属性未正确终止],其根本原因是org.apache.jasper.JasperException:/WEB-INF/tags/config.tag(行:27,列:12)“的属性未正确终止。

I note column 12 is the first quotation … 我注意到第12列是第一个引号...

To be clear, escaping in the JSTL expression seems to be the root cause - but why is it not working on a newer Tomcat? 需要明确的是,转义JSTL表达式似乎是根本原因-但是为什么它不适用于较新的Tomcat?

If your storageType variable really is a boolean, you can check it like so: 如果您的storageType变量确实是布尔值,则可以这样检查它:

<c:if test="${storageType eq false}">

If however it's just a string with value 'false' you should do a string comparison: 但是,如果它只是一个值为'false'的字符串,则应该进行字符串比较:

<c:if test="${storageType eq 'false'}">

Considering your particular example, you could do something like this: 考虑到您的特定示例,您可以执行以下操作:

<c:when test="${storageType eq true || storageType eq false}">

or for string comparrison 或用于弦乐

<c:when test="${storageType eq 'true' || storageType eq 'false'}">

But you really should first perform the first checks to see if your variable really is a boolean type and not just a string. 但是您确实应该首先执行第一次检查,以查看您的变量是否确实是布尔类型而不是字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM