避免在 JSP 标记中嵌套单引号或双引号

如果单引号嵌套在单引号中,或者双引号嵌套在双引号中,那么此规则会对 JSP 标记进行标记。

示例 1:
<c:if test="<%=(link.indexOf(':') == -1)%>" >

在本示例中,test 属性包含的字符序列 ':' 嵌套在外层单引号中 '<%=(link.indexOf(':') == -1)%>'。 此规则会标记本示例。

在源扫描程序中,为此规则提供了快速修订。 此快速修订对嵌套的引号进行转义。 在本示例中,将对 ':' 周围的引号进行转义。

应用了快速修订的示例 1:
<c:if test="<%=(link.indexOf(\':\') == -1)%>" >

在 JSP 标记中嵌套引号会导致类似以下示例的错误消息:

Error Message:JSPG0048E: Page failed to validate using taglib validator for ... : org.xml.sax.SAXParseException: Attribute name "jsp:id" associated with an element type "c:if" must be followed by the " = " character.
Root Cause:com.ibm.ws.jsp.translator.JspTranslationException: JSPG0048E: Page failed to validate using taglib validator for...

有关更多信息,请参阅: