This article illustrates the access path of Java Web development. Share to everyone for your reference. Specifically as follows:
Web applications are composed of a large number of files, systems, and other operations mainly rely on the mutual call between files to complete, the call is based on the location of the file to determine. If you are accessing a file, the system reports the following error, if your file name is not wrong, the path is wrong.
To illustrate the path problem, we assume that the following document structure is available:
This is a screenshot under JBuilder2006, the application of the name is Filepathweb, there are two folders, AA and BB, of which AA under a_a.jsp and a_b.jsp two files, BB under the b_a.jsp file.
Absolute path
The basic format for Web file access is as follows:
Protocol://HOST: Port/Application name/folder name/file
Protocol: This should be the HTTP protocol;
Host: Is the address of the server running the Web application, you can use the host name (or domain name), you can use the IP address, if this machine, you can use the virtual IP address (127.0.0.1), you can use the machine name.
Port: The port used by the Web server to run, and each server program will have a port. For Web applications, the default port is 80.
Application Name: Multiple Web applications may be running on the same application server, which is allowed, when we visit an application, we need to specify the Web application we are accessing, which is usually the name of the Web application folder, but it can be configured as something else. application configuration See Web application Deployment related content.
Folder name: In the same Web application, you might create a different folder to store the files of different functions based on different functions, and you must specify the folder in which you want to access the file.
File: The JSP file to access.
Note that the folder name and file name together determine the file, which is equivalent to the full path of the file. Access to the servlet uses not the filename, but the path configured in Web.xml to take part in the servlet section.
Example: How to access the a_a.jsp file in the above Web application, assuming that access on this computer, using the port is 8083, deployment of the use of the name of the application is filepathweb.
The path should be written like this:
http://127.0.01:8083/filepathweb/aa/a_a.jsp
Or
http://localhost:8083/filepathweb/aa/a_a.jsp
Several questions need to be explained:
(1) Some people say that the internet is never required to enter the port, because the default port is used, the Web application's default port is 80.
(2) Some people say that you never need to enter the name of the application, because the default application is set, and for the default application please refer to the other relevant content in this book.
(3) Some people say, also do not need to enter the file name to access, because set the Welcome page, set in the Web.xml, in this part of the content, please refer to the other relevant content in this book.
Relative path
The above describes the way to access a file, where the way to access a stunning path, that is, we use the full path, in the Web application files to each other, in addition to the use of absolute path, you can also use relative paths. For example, we want to access the a_b.jsp in the a_a.jsp file, directly write the absolute path is certainly no problem, but not easy to write, and if the deployment of the Web application name changes, access to the path need to change, so we should use the relative path.
There are two kinds of relative paths: the first, the position relative to the current file, and the second, relative to the position of the application.
Relative paths need to know the following when they are in use:
(1) The current path is ".", which represents the current path.
(2) The previous path is ".." and to access the previous folder, you need to write ". /"。
(3) Write "/" directly relative to the path of the application.
There are 3 ways to access a_b.jsp in the a_a.jsp file, depending on the situation above (via the hyperlink):
<a href= "a_b.jsp" >a_b.jsp</a><br>
<a href= "http://localhost:8083/filepathweb/aa/a_b.jsp" >a_b.jsp</a><br>
<a href= "/filepathweb/aa/a_b.jsp" >a_b.jsp</a><br>
The first case is the relative path, because a_a.jsp and a_b.jsp are in the same folder, so write a_b.jsp directly, and the system will look for a_b.jsp in the folder where A_a.jsp is located, using the path relative to the current file.
In the second case, the absolute path is used, as described earlier.
In the third case, use the location information of the application, and then just write it in the application position.
This is the case of accessing the same file, what if you want to access the files in different folders? For example, to access the b_a.jsp in the BB folder in a_a.jsp.
For b_a.jsp access in BB, the second and third of the 3 methods used above can also be used directly, but the path relative to the current file is troublesome, following are 3 ways to access b_a.jsp in a_a.jsp:
<a href= "./... /bb/b_a.jsp ">a_b.jsp</a><br>
<a href= "http://localhost:8083/testweb/bb/b_a.jsp" >a_b.jsp</a><br>
<a href= "/testweb/bb/b_a.jsp" >a_b.jsp</a><br>
What you need to explain is relative to the path, and if the current folder is deep, you can use it more than once. /","./"represents the current folder.
I hope this article will help you with the JSP program design.