【问题标题】:NetBeans report error in src="<%=request.getContextPath()%>/images/image.png" in JSPNetBeans 在 JSP 中的 src="<%=request.getContextPath()%>/images/image.png" 报错
【发布时间】:2014-11-13 08:24:31
【问题描述】:

我所拥有的任何地方:

<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。 ${pageContext.servletContext.contextPath}

标签: java jsp jakarta-ee netbeans el


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 2018-11-16
    • 2023-02-08
    • 2014-02-25
    • 2012-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多