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