NetBeans报告src ="<%= request.getContextPath()%> / images/image.png"在JSP中

时间:2014-11-13 08:24:32

标签: java jsp java-ee netbeans el

我所拥有的任何地方:

<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)

我怎样摆脱它?

1 个答案:

答案 0 :(得分:1)

不要在JSP文件中使用Java代码。使用JSTL。您可以使用以下代码获取上下文路径

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

${pageContext.servletContext.contextPath}
// OR
${pageContext.request.contextPath}

详细了解 Comparing JSTL and JSP Scriptlet Programming