Access Path Problem Analysis for Java Web development, javaweb

Source: Internet
Author: User

Access Path Problem Analysis for Java Web development, javaweb

This example describes the access path of Java Web development. Share it with you for your reference. The details are as follows:

A Web application is composed of a large number of files. The system and other operations mainly rely on mutual calls between files. The call is determined based on the file location. When you access a file, the system reports the following error. If your file name is not written incorrectly, the path is incorrect.

To illustrate the path problem, we assume that the following document structure is available:

This is one in JBuilder2006. The application name is filepathweb. There are two folders, aa and bb. There are a_a.jsp and a_ B .jsp files under aa, and B _a.jsp files under bb.

Absolute path

The basic format of Web file access is as follows:

Protocol: // host: Port/Application name/folder name/File
Protocol: Here it should be the http protocol;
HOST: it is the address of the server running the Web application. You can use the host name (or domain name) or IP address. If it is a local machine, you can use the virtual IP address (127.0.0.1 ), you can use the machine name.
Port: the port used when the Web server is running. Each server program has a port. For Web applications, the default port is 80.
Application name: multiple Web applications may run on the same application server. This is allowed. when accessing an application, we need to specify the accessed Web application, this path is usually the name of the Web application folder, but can be configured as another path. For application configuration, see Web application deployment.
Folder name: In the same Web application, different folders may be created based on different functions to store files of different functional modules. to access this file, you must specify the folder where it is located.
File: the jsp file to be accessed.

Note that the folder name and file name determine the file, which is equivalent to the complete path of the file. For Servlet access, the path configured in web. xml is not the file name, but can be part of the Servlet content.

For example, how to access the_a.jsp file in the Web application above. Assume that the port used for access on the local machine is 8083, and the Application name used for deployment is filepathweb.

The path should be written as follows:
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 you never need to enter a port when accessing the internet because the default port is used and the default port of the Web application is 80.
(2) It is said that you never need to enter the application name because the default application is set. For more information about the default application, see other relevant content in this book.
(3) Some people say that they do not need to enter the name of the file to be accessed because the welcome page is set up on the web. for more information about the content set in xml, see other related content in this book.

Relative Path

The above describes how to access a certain file. The access method here is called absolute path, that is, when we use the complete path to access each other's web application files, in addition to absolute paths, relative paths can also be used. For example, if we want to access a_ B .jsp IN THE a_a.jsp file and directly write the absolute path, it is certainly no problem, but it is not easy to write. In addition, if the Web application name changes during deployment, the access path must be changed, so we should use the relative path.

There are two types of relative paths: first, relative to the current file location; second, relative to the application location.

When using relative paths, you need to know the following:
(1) The current path is ".", indicating the current path.
(2) The upper-level path is "..". To access the upper-level folder, you need to write "./../".
(3) directly write "/" relative to the Application Path "/".

According to the above situation, there are three methods to access a_ B .jsp IN THE a_a.jsp file (via 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, write a_ B .jsp directly. The system will search for a_ B .jsp in the folder where a_a.jsp is located, and the path relative to the current file is used.
In the second case, the absolute path is used, which is described earlier.
In the third case, the application's location information is used, and you only need to write the information in the application's location.

This is the case of accessing the same file. What should I do if I want to access files in different folders? For example, you need to access B _a.jsp In the bb folder in a_a.jsp.

For access to B _a.jsp in bb, the second and third methods in the preceding three methods can be used directly, but it is more troublesome than the current file path, the following are three methods 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>

It must be noted that, if the current folder is relatively deep, you can use "../", "./" multiple times to indicate the current folder.

I hope this article will help you with JSP program design.

Related Article

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.