Summary of Path Problems in Java Web Development

Source: Internet
Author: User

(1)WebSeveral Basic concepts of path in development

Assume that the following page is accessed in the browser,1As shown in: 

Figure1

EclipseDirectory structure2As shown in:

 

Figure2

The basic concepts of the website are described as follows:

1.WebRoot directory of the site:Http: // localhost: 8080/

2.WebApplicationProgramThe root directory:Http: // localhost: 8080/test/

3.Same level directory:Http: // localhost: 8080/test/articles/article1.jspAndHttp: // localhost: 8080/test/articles/article2.jsp Is in the same level directory.

 

2. return values of several path-related functions:

InTesturl. jspThe file Tests Three path-related functions:

1.Getrequesturi ()

2.Getcontextpath ()

3.Getservletpath ()

Result3As shown in:

 

Figure3

III.Web. xmlPath in

servlet ing /XX "/" indicates the current Web root path of the application.

If you think about this, you can draw a conclusion: AllWeb. xmlAll files describe a specificWebApplication Deployment information,/"Can only represent the currentWebThe root path of the application, instead of pointingWebRoot directory of the site

4. Path Problems in forwarding and redirection

1. if no" / " , for example, request. getrequestdispatcher ("hello. JSP "). forward (request, response) and response. sendredirect ("hello. JSP ") indicates searching in the same level directory login. JSP file.

2.If the path contains"/"(Note:"/"Is the first"/")

A,Forwarding

For exampleRequest. getrequestdispatcher ("/Hello. jsp"). Forward (request, response): RepresentsHttp: // localhost: 8080/test/Directory SearchHello. jspFile.

B,Redirection

For exampleResponse. sendredirect ("/Hello. jsp "): RepresentsHttp: // localhost: 8080/ Search under directoryHello. jspFile

 

5.

or " /xxx " > path

" / " indicates Web root path of the site . .

because Hyperlinks can be linked to any required target resource , SO / it definitely does not represent the current Web Root path used , but the current Web root path of the site.

6.PageTagErrorpageAttribute Path Problems

ErrorpageIf the attribute value is"/"Start,Relative to the currentWebThe root directory of the application. Otherwise, it is relative to the current page.

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.