Issue
I am trying to use the request.getRealPath("/") to get the Path for the resource files in JSP page. But i get below error when i try to run the page in Eclipse.
<jsp:setProperty name="LIILLog" property="configPath" value="<%=request.getRealPath("/")%>"/>
The error which i get is as below:
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)
I am using a Maven Project in Eclipse and Tomcat 8.5 server.
Solution
Your problem is exactly what the error says, you need to escape the quotes or use single quotes:
Do this:
value='<%=request.getRealPath("/")%>'
or (don't) do this (it is ugly):
value="<%=request.getRealPath(\"/\")%>"
Answered By - mikeb
Answer Checked By - Pedro (JavaFixing Volunteer)