在JSP页面中使用request.getRealPath(“ /”)时出现错误

问题描述 投票:-3回答:1

我正在尝试使用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项目。

java jsp servlets
1个回答
1
投票

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

执行此操作:

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.