在 JSP 页面中使用 request.getRealPath("/") 时出错

Getting Error While Using request.getRealPath("/") in JSP Page

我正在尝试使用 request.getRealPath("/") 获取 JSP 页面中资源文件的路径。但是当我尝试 运行 Eclipse 中的页面时出现以下错误。

<jsp:setProperty name="LIILLog" property="configPath" value="<%=request.getRealPath("/")%>"/>

我得到的错误如下:

May 31, 2020 7:58:03 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/LHC] threw exception [/lhc_admin_login.jsp (line: [28], column: [64]) Attribute value [request.getRealPath("/")] is quoted with ["] which must be escaped when used within the value] with root cause
org.apache.jasper.JasperException: /lhc_admin_login.jsp (line: [28], column: [64]) Attribute value [request.getRealPath("/")] is quoted with ["] which must be escaped when used within the value
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)
    at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:291)
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:97)
    at org.apache.jasper.compiler.Parser.parseAttributeValue(Parser.java:303)
    at org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:247)
    at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:168)

我在 Eclipse 和 Tomcat 8.5 服务器中使用 Maven 项目。

你的问题正是错误所说的,你需要转义引号或使用单引号:

这样做:

value='<%=request.getRealPath("/")%>'

或者(不)这样做(很丑):

value="<%=request.getRealPath(\"/\")%>"