Issue
What is the difference between these two?
In JSP:
${pageContext.request.contextPath}
and how to achieve same results if coded without Expression Language and in a servlet?
request.getServletPath()
and how to achieve same results if coded in JSP?
Solution
${pageContext.request.contextPath} : Returns the portion of the request URI that indicates the context of the request. In fact, it is identical to request.getContextPath()
, since ${pageContext.request}
refers to the HttpServletRequest
of the current request.
For example:
http://localhost:80/myapplication/path/servlet
${pageContext.request.contextPath}
returns/myapplication
request.getServletPath()
Returns the part of this request's URL that calls the servlet, e.g./path/servlet
${pageContext.request.servletPath}
returns/path/servlet
Answered By - Ramesh PVK
Answer Checked By - Mary Flores (JavaFixing Volunteer)