The question here is that both PageContext and request are one of the built-in objects in the JSP, so why not just use ${request.contextpath} to get the project path?
The problem is that the built-in object of the JSP is confused with the built-in object of the El expression.
9 large built-in objects for JSPs:
Application: is an instance of ServletContext that represents the Web project itself that the JSP belongs to
Config: is an instance of ServletConfig that represents the configuration information for the current JSP
Exception: is an instance of java.lang.Throwable that can be used only if Iserrorpage is set to true in the JSP page
An instance of Out:jspwriter that represents the output stream of a JSP page
Page: Represents the pages themselves, not much use
PageContext: Page Context Object
Request: is an instance of HttpServletRequest, representing a single request
Response: is an instance of HttpServletResponse that represents the response of the server
Session: Is an instance of HttpSession, representing a session
11 built-in objects of the El Expression: (el expression format ${expression}, which is a simple way to access data in order to be introduced in a JSP page without using the Java scripting language)
PageContext: The PageContext object representing the page, same as the PageContext object of the JSP
Pagescope: Used to get property values in the page range
Requestscope: Used to get the value of a property within the request scope
Responsescope: Used to get property values in the response range
Sessionscope: Used to get the value of the attribute in the session range
Applicationscope: Used to get property values in the application range
Param and Paramvalues: The parameter value used to get the request
Header and Headervalues: used to get request header information
Cookie: Used to get the value in a cookie
Initparam: Used to get initialization information for a web App
From the comparison above, it is not difficult to find that the El expression has only the PageContext object, and without the request object, the request object is the built-in object of the JSP. The request object is obtained in the El expression only through ${pagecontext.request}, and similarly, the response and session objects are obtained. So when getting the absolute path of the project, it can only be obtained by ${pagecontext.request.contextpath}, which corresponds to the <%=request.getcontextpath ()%> in the Java scripting language
about why you must use ${pagecontext.request.contextpath} to get the project path in a JSP page, but not with ${request.contextpath}?