Request. getcontextpath () indicates/project name. Example:/news01
1. jump from the JSP page to another page or Servlet
Use the full path (/project name/file path) to jump from the JSP page to other pages ). For example, the project name is news01, and the page Directory is as follows:
1) For example, jump from the index. jsp page to the list. jsp page under the main Folder:
Link path:/news01/main/list. jsp
2) For example, jump from the index. jsp page to your own page:
Link path:/news01/index. jsp
3) For example, jump from the list. jsp page to the index. jsp page:
Link path:/news01/index. jsp
4) for example, jump from the list. jsp page to the insert. jsp page.
Link path:/news/main/insert. jsp
5) The servlet URL is/servlet/testservlet.
The link to the servlet jump from any JSP page is/news01/servlet/testservlet
6) The servlet URL is/testservlet.
The link to the servlet jump from any JSP page is/news01/testservlet
7) Example of the Form Action path:
<Form action = "/news01/servlet/loginservlet" method = "Post">
Ii. jump from servlet to JSP page
(1) Use the requestdispatcher method:
1. Single Layer: The servlet URL is in the root directory (it does not need to start with a slash)
(1) From testservlet (urlpattern:/testservlet) to index. jsp under the root directory
The jump statement is:
Request. gerrequestdispatcher ("index. jsp"). Forward (request, response );
(2) From testservlet (urlpattern:/testservlet) to list. jsp under the main directory
The jump statement is:
Request. gerrequestdispatcher ("Main/list. jsp"). Forward (request, response );
2. Double or multi-layer: the servlet URL is under the root directory (start with a slash, and the slash here represents the current application-this project represents/news01/
(1) From testservlet (urlpattern:/servlet/testservlet) to index. jsp under the root directory
The jump statement is:
Method 1: Relative Path
Request. gerrequestdispatcher ("../index. jsp"). Forward (request, response );
Method 2: Start with a slash
Request. gerrequestdispatcher ("/index. jsp"). Forward (request, response );
(3) from testservlet (urlpattern:/servlet/testservlet) to list. jsp in the main directory
The jump statement is:
Method 1: Relative Path
Request. gerrequestdispatcher ("../main/list. jsp"). Forward (request, response );
Method 2: Start with a slash
Request. gerrequestdispatcher ("/main/list. jsp"). Forward (request, response );
(2) Use response. sendredirect ()
Whether the servlet is a single layer or a double layer, use the following method:
Response. sendredirect ("/news01/index. jsp ");
Response. sendredirect ("/news01/main/list. jsp ");
Request. getcontextpath () indicates the/project name. Example:/news01
Response. sendredirect (request. getcontextpath () + "/main/list. jsp ");
Response. sendredirect (request. getcontextpath () + "/index. jsp ");