(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.