About the path of Servlet forwarding to JSP pages (mandatory), servletjsp
I. phenomena and concepts
1. Problem
When the Servlet is forwarded to the JSP page, the Servlet Path is displayed in the address bar of the browser, if the JSP page hyperlink is relative to the JSP page address and the Servlet and the JSP page are not in the same folder, the path is messy.
2. absolute path Concept
The path relative to the contextPath (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 before it.
<a href="<%= request.getContextPath() %>/TestServlet" rel="external nofollow" >To B</a>
Ii. Summary of '/' in Java Web Development
1. root path of the current Web Application
'/' Indicates http: // localhost: 8080/contextPath/: address processed by Servlet
1) forwarding: request. getRequestDispatcher ("/path/B. jsp"). forword (request, response );
2) map Servlet access paths in the web. xml file
<servlet-mapping> <servlet-name>TestServlet</servlet-name> <url-pattern>/TestServlet</url-pattern></servlet-mapping>
3) '/' in various custom labels '/'.
2. root path of the Web site
'/' Indicates http: // localhost: 8080/: address processed by the browser
1) hyperlink: <a href = "/TestServlet" rel = "external nofollow"> To B </a>
2) action in the form Tag: <form action = "/B. jsp">
3) redirection: response. sendRedirect ("/B. jsp ");
The above discussion about the path of Servlet forwarding to the JSP page (mandatory) is all the content shared by the editor. I hope you can give us a reference and support for the house of friends.