project path problem

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

This statement is used to assemble the relative path of the current web page.

<base href="<%=basePath%>"> is used to indicate the root path used by the relative path of the current page. Put it in <head></head>
For example, if there is a connection inside the page, the full path should be http://localhost:80/myblog/authen/login.do
where http://server/ is the base path of the server , myblog is the name of the current application, then, my root path should be http://localhost:80/myblog/.

After having this <base ... >, I don't want to write the full path to the connection of my page content, I just need to write authen/login.do. The server will automatically assemble the path specified by <base ...> and the relative path in the page to form a complete path.
If there is no <base...>, then the link of my page must write the full path, otherwise the server will not find it.

request.getSchema() can return the protocol used by the current page, which is "http" in the above example.
request.getServerName() can return the name of the server where the current page is located, which is "localhost" in the above example.
request.getServerPort() can Returns the port used by the server where the current page is located, which is 80. request.getContextPath() can return the name of the application where the current page is located, which is the four assembled
myblog in the above example, which is the current application path.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325903461&siteId=291194637