[Original]java Web learning note 35:java on absolute path and relative path issues in the Web

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.