When the Servlet is forwarded to the JSP page, the path of the Servlet is displayed on the browser address bar. , and if the hyperlink of the JSP page is still relative to the address of the JSP page and the Servlet and the JSP page are not in the same folder, there will be a path confusion problem.
The path relative to contextPath (the context of the current Web application).
Solution: Use absolute paths instead of relative paths for hyperlinks. If / represents the root directory of the site, add contextPath in front of it.
<a href="<%= request.getContextPath() %>/TestServlet">To B</a>
'/' represents http://localhost:8080/contextPath/ : the address processed by the Servlet
1) Forwarding: request.getRequestDispatcher("/path /b.jsp").forword(request, response);
2) Mapping Servlet access path in web.xml file
<servlet-mapping><servlet-name>TestServlet</servlet-name><url-pattern>/TestServlet</url-pattern></servlet-mapping>
3) Various custom tags middle'/'.
'/' represents http://localhost:8080/: the address processed by the browser
1) Hyperlink: /TestServlet">To B
2) Action in form tag: