Relative and absolute paths in jsp

1. Relative path

   For relative files:

   a.html page <link rel="stylesheet" href="font.css" type="text/css" />, font.css and a.html are in the same directory.

  Relative to the server:

  <link rel="stylesheet" href="/font.css" type="text/css" />, the address should start with "/".

  Writing url in ajax: 'getUser'

2. Absolute path:

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

<base href="<%=basePath%>">

<link rel="stylesheet" href="font.css" type="text/css" />,相对于base。

ajax中写法 url:‘<%=basePath%>getUser’

 

Guess you like

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