I have been engaged in Java web development for more than a year, and it is inevitable to write html or jsp pages. The powerful function of web applications lies in their hyperlinks (Hyper Link). For example, page a saves the link address (that is, URI) pointing to page b, but the problem lies precisely here, how to correctly reference a file. For example, how do you reference another HTML page as a hyperlink in an HTML page? How to insert a picture into a web page? ...... In addition, relative paths are very popular in struts, so it is easy to get confused if you are not careful. If you use the wrong file path when referencing a file (such as adding a hyperlink or inserting a picture, etc.), the reference will become invalid (the linked file cannot be browsed, or the inserted picture cannot be displayed, etc.). In order to avoid these errors and cite the documents correctly, I have written down the differences and usages for future reference. HTML has two ways of writing paths: relative paths and absolute paths HTML relative path File references in the same directory If the source file and the referenced file are in the same directory, just write the referenced file name. We now create a source file info.HTML, and reference the index.HTML file as a hyperlink in info.HTML. Assume that the path to info.HTML is: d:\tomcat\webapps\hello\blabla\info.HTML Assume that the path to index.HTML is: d:\tomcat\webapps\hello\blabla\index.HTML The code to add a hyperlink to index.HTML in info.HTML should be written like this: Copy code The code is as follows:<a href = "index.HTML">index.HTML</a> How to indicate the parent directory ../ represents the parent directory of the source file, ../../ represents the parent directory of the source file, and so on. Assume that the path to info.HTML is: d:\tomcat\webapps\hello\blabla\info.HTML Assume that the path to index.HTML is: d:\tomcat\webapps\hello\index.HTML The code to add a hyperlink to index.HTML in info.HTML should be written like this: Copy code The code is as follows:<a href = "../index.HTML">index.HTML</a> Assume that the path of info.HTML is: d:\tomcat\webapps\hello\blabla\wowstory\info.HTML Assume that the path to index.HTML is: d:\tomcat\webapps\hello\index.HTML The code to add a hyperlink to index.HTML in info.HTML should be written like this: Copy code The code is as follows:<a href = "../../index.HTML">index.HTML</a> Assume that the path to info.HTML is: d:\tomcat\webapps\hello\blabla\info.HTML Assume that the index.HTML path is: d:\tomcat\webapps\hello\wowstory\index.HTML The code to add a hyperlink to index.HTML in info.HTML should be written like this: Copy code The code is as follows:<a href = "../wowstory/index.HTML">index.HTML</a> How to represent a sub-directory <br />To reference a file in a sub-directory, simply write the path of the sub-directory file. Assume that the path to info.HTML is: d:\tomcat\webapps\hello\blabla\info.HTML Assume that the path to index.HTML is: d:\tomcat\webapps\hello\blabla\HTML\index.HTML The code to add a hyperlink to index.HTML in info.HTML should be written like this: Copy code The code is as follows:<a href = "HTML/index.HTML">index.HTML</a> Assume that the path to info.HTML is: d:\tomcat\webapps\hello\blabla\info.HTML Assume that the path to index.HTML is: d:\tomcat\webapps\hello\blabla\HTML\tutorials\index.HTML The code to add a hyperlink to index.HTML in info.HTML should be written like this: Copy code The code is as follows:<a href = "HTML/tutorials/index.HTML">index.HTML</a> HTML absolute path HTML absolute path refers to the complete path of the file with the domain name. Suppose you have registered the domain name www.jb51.net and applied for a virtual host. The virtual host provider will give you a directory, such as www. This www is the root directory of the website. Assume that there is a file index.HTML in the www root directory. The absolute path of this file is: https://www.jb51.net/index.html. Suppose a directory called HTML_tutorials is created in the www root directory, and then a file index.HTML is placed in this directory. The absolute path of this file is https://www.jb51.net/article/32759.htm. |
<<: JavaScript imitates the complete page implementation process of Xiaomi Mall official website
>>: Teach you how to make cool barcode effects
I recently came into contact with MySQL. Yesterda...
1. What is a two-column layout? There are two typ...
The <TH> tag is used to set the properties ...
1. Check the MySQL database encoding mysql -u use...
When using Animation.css, I found that the font o...
This article describes how to install Apache on a...
A transaction is a logical group of operations. E...
When discussing Web standards, one thing that alwa...
This article introduces RHEL8 network services an...
Editor: This article discusses the role that inte...
Within rows, light border colors can be defined i...
vue implements the drag and drop sorting function...
The network configuration of Host Only+NAT mode u...
The role of the interface: Interface, in English:...
Table of contents Preface Background data splicin...