One, relative path and absolute path
1. Relative path:
Relative path refers to the path relative to the directory where the current file is located!
2. Absolute path:
An absolute path is represented by A/start
when the browser resolves ,/Represents theroot directory of the http://localhost:8080/"server"
when the server resolves ,/represents the HTTP://LOCALHOST:8080/project name/ "Project root directory"
1) Common paths:
Url-pattern:
Path to forward:
Both paths are parsed by the server side, or represent the root directory of the project
Redirected paths
The path in the page
Both of these paths are resolved by the browser side,/the root directory of the server
Related knowledge:
When a Java WEB project is published, it actually deploys only the WebContent folder to the server and the folder name WebContent to the project name, and the Java source code is not published but runs in webcontent->web-inf-> The compiled class bytecode file in the classes directory.
Therefore, the project root directory mentioned above refers to: directory path to WebContent
Second, practical application:
In practical development, we generally recommend using absolute paths
If you want to use a relative path in the page, you can add the <base/> tag in page
<base> tags
<!--the base tag consists of an HREF attribute, which can be used as a prefix for our relative paths in the page
That is: The relative path we write on the current page, which defaults to the href in the base tag
property value as a prefix, so the base tag lets us use the absolute path in a way that uses a relative path!
The base tag works only on relative paths and does not work on absolute paths! -
<base href= "http://localhost:8080/servlet01/html/"/>
Analysis of relative path and absolute path in Java Web