Analysis of relative path and absolute path in Java Web

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.