Summary of path-related problems in Java WEB development

Source: Internet
Author: User

Summary of PATH problems in Java Web development

(1) Web several basic concepts of path in development

Let's say you have access to the following page in your browser, as shown in 1:

Figure 1

The directory structure in Eclipse 2 shows:

Figure 2

Then several basic concepts for this site are expressed as follows:

1. Web site root directory : http://localhost:8080/

2. root directory of the Web application:http://localhost:8080/test/

3. Sibling Directories: http://localhost:8080/test/articles/article1.jsp and http://localhost:8080/test/articles/ Article2.jsp is in the same sibling directory .

Two Return values for several path-related functions:

Three path correlation functions were tested in the testurl.jsp file:

1. Getrequesturi ()

2. Getcontextpath ()

3. Getservletpath ()

As shown in result 3:

Figure 3

three. path in Web. XML

The "/" in Servlet mapping <url-pattern>/xx</url-pattern> represents the root path of the current web App.

Just think about it and come to the conclusion that all of the Web. xml files describe the deployment-related information for a particular website, so "/" can only represent the root path of the current web app, not the root directory of the Web site.

Four Routing issues in forwarding and redirection

1. If there is no "/", such as Request.getrequestdispatcher ("hello.jsp"). Forward (request, response) and Response.sendredirect (" Hello.jsp ") means looking for the login.jsp file in the sibling directory.

2. If the path contains "/" (Note that "/" here refers to the first "/" in the path)

A, forward

such as Request.getrequestdispatcher ("/hello.jsp"). Forward (request, Response): Delegate to http://localhost:8080/test/ The following directory looks for the hello.jsp file.

B, redirect

such as Response.sendredirect ("/hello.jsp"): representative to http://localhost:8080/directory looking for hello.jsp file

Five. <form action= "/xxx" > or <a href="/xxx"> paths in </a>

"/" represents the root path of the Web site:

Because hyperlinks can be linked to any desired target resource, the/Representative is definitely not the root path of the current web app, but the root path of the current Web site.

Six. path problem for errorpage property in Page label

The value of the ErrorPage property, expressed as a "/", indicates relative to the current Web application's root directory, otherwise, represents the corresponding page.

Summary of path-related problems in Java WEB development

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.