我所到之处:
<img alt="image" src="<%=request.getContextPath()%>/images/image.png" >
NetBeans 报告错误:
Bad value " /images/image.png" for attribute "src" on element "img": WHITESPACE in PATH.
Syntax of IRI reference:
Any URL. For example: '/hello', '#canvas', or 'http://example.org/'. Characters should be represented in NFC and spaces should be escaped as '%20'.
From line 42, column 21; to line 42, column 64
(Rule Category: Attributes)
如何摆脱它?
最佳答案
不要在 JSP 文件中使用 Java 代码。使用JSTL。您可以使用下面的代码获取上下文路径
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
${pageContext.servletContext.contextPath}
// OR
${pageContext.request.contextPath}
关于java - NetBeans 在 JSP 中的 src ="<%=request.getContextPath()%>/images/image.png"中报告错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26904283/