spring mvc 项目 "invalid character used in text string" .jsp 文件中的错误

spring mvc project "invalid character used in text string" error in .jsp file

我想在我的网站上分享我的示例代码。我在 jsp 文件中使用了标点符号(例如;&、*、% 等),如下所示;

<pre>
/*
if(sensB>sensA && diffB>200)
{
ctr++;
delay(2500); // INCREMENT
}
*/
</pre>

但是我收到了警告;

Description Resource Path Location Type Invalid character used in text string (/if(sensB>sensA && diffB>200) { ctr++; delay(2500); // INCREMENT }/)

我怎样才能得到这个错误?

正如评论中提到的 shi 您需要在 JSP

中转义您的内容(代码字符串)
<c:out value="${myCodeString}"/>

还有一个选项:

<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
${fn:escapeXml(myCodeString)}

来自 How can I escape special HTML characters in JSP?