Path problem Java Web projects

In javaweb project, the routing problem is very common, comparing the situation to do the redirection or forwarding resources, etc., need to use the path. So how should the path to judge it. In javaweb path can be divided into two categories.

  1. Relative path: not determined only by the relative path resources

    • For example ./index.html, img/1.pngshaped like form such a path, not to /the beginning of the path. Like when we visited picture of resource path, a relative path is used.

      Here Insert Picture Description

    • Usage: find the relative position relationship between the current source and target resources

      • ./: Indicates the current directory
      • ../: Indicates the parent directory
  2. Absolute path: resources can be determined only by the absolute path

    • such as:https://www.csdn.net/

      Here Insert Picture Description

    • Or this:/path/test

      Here Insert Picture Description

    • Law: The /Path is the absolute path beginning.

    • Usage: to change the path from where the judge sent, who used to give.

      • If it is to use a browser or client, you need to add virtual directory (access path of the project), dynamic access to the virtual directory through normally. request.getContextPath(). For example, when doing the redirect.
      • Internal server to use, then you can ignore the virtual directory. For example resources to do the forwarding of the time.
Published 58 original articles · won praise 61 · views 50000 +

Guess you like

Origin blog.csdn.net/qq_43058685/article/details/104403427