this blog is original: Integrated still Silicon Valley (http://www.atguigu.com) System tutorial (deep thank) and network of existing resources (blogs, documents, books, etc.), the source of resources I will markThe purpose of this blog: ① summary of their own learning process, equivalent to study notes ② to share their own experience to everyone, learn from each other, communication, not commercialcontent inevitably appear problems, welcome to correct, exchange, discussion, you can leave a message, can also be contacted by the following ways. I Internet technology enthusiasts, Internet technology enthusiastsWeibo: Ivan is in 0221qq:951226918
--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- -----------------------------
1. Problems with absolute paths
1) It is recommended to write "absolute path" when developing: absolute path must be written, but writing relative path may cause problems.
When the servlet is transferred to the JSP page, the path of the servlet is displayed on the browser address bar, and if the JSP page's hyperlink is relative to the address of the JSP page, the problem of path confusion occurs.
2) write an absolute path to avoid the above problems:
① in Javaweb what is called "right path": the path to the root path (contextpath) of the current web App . That is, any path must be brought on ContextPath
such as: Http://localhost:8080/javaWEB (ContextPath, the context of the current Web application)/a.jsp
② How to write: if/on behalf of the site directory, then add ContextPath in front can
Request.getcontextpath ();
Application.getcontextpath ();
3) What does Javaweb develop / represent?
① the root path of the current web app: http://localhost:8080/contextPath/: if/need to cross the servlet container to handle
> Request Forwarding: Request.getrequestdispatcher ("/b.jsp"). Forward (Request,response);
> in the Web. xml file, map the servlet access path:
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/TestServlet</url-pattern>
</servlet-mapping>
> in various custom labels
Root path of ②web site: http://localhost:8080/: If/by browser
> Hyperlinks: <a href= "/testservlet" > Hyperlinks </a>
> Action:<form action= "/login.jsp" in the form ></form>
> When requesting redirection: Response.sendrdirect ("/a.jsp")
[Original]java Web learning note 35:java about absolute and relative path issues in the Web