Two methods for obtaining the path in jsp, the method for obtaining the url path (recommended), and jspurl
<% = Request. getContextPath () %> solves the relative path problem and returns the root path of the site.
<A href = "<% = request. getContextPath () %>/XXX. jsp"> // obtain the absolute path.
<A href = "XXX. jsp"> // obtain the relative path.
<A href = "<% = request. getContextPath () %>/XXXX. jsp"> effectively prevents connection failures.
Request. getContextPath () obtains the project name. If the project is the root directory, a "", that is, an empty string. If the project is dzjc, <% = request. getContextPath () %>/returns dzjc/, and the server path is automatically added. <a href = "XXX. jsp "> it should be the xxx in the current path. for jsp pages, you can also set html: base in the head to solve the path problem, but the most commonly used is request. getContextPath.
If you want to obtain the actual physical path of the project file, you can use: <% = request. getRealPath ("/") %> to output: d: \ web \
The request. getRealPath ("") method is no longer recommended.
This. getServletContext (). getRealPath ("/") to obtain the actual physical path of the project file, that is, to obtain the uri path from the absolute address. this method is
The method in HttpServletRequest's decoration class HttpServletRequestWrapper (using the decoration mode) String url = request. getRequestURI ();
System. out. println (url); // output/2/LoginServlet project name + url of the current execution page
The above two methods for obtaining the path and the method for obtaining the url path (recommended) in jsp are all the content shared by Alibaba Cloud. I hope to give you a reference, we also hope that you can support the customer's home.