Java EE page Get path

Source: Internet
Author: User

<% String Path = Request.getcontextpath (); String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/"; %>

This statement is used to assemble the relative path of the current page.
<base href= "..." > is the root path used to indicate the relative path of the current page. For example, there is a connection inside the page, the complete path should be http://localhost:80/myblog/authen/login.do where http://server/is the basic path of the server, MyBlog is the name of the current application, My root path should be so http://localhost:80/myblog/.
With this <base ... > after the connection of my page content, I do not want to write the full path, I just write authen/login.do on it. The server will automatically assemble the path specified by <base ...> and the relative path within the page to form the full path. If there is no such <base...>, then the link of my page must write the full path, otherwise the server will not be found.
Request.getschema () can return the protocol used by the current page, or the "http" Request.getservername () in the example above can return the name of the server on which the current page is located, or "localhost" in the example above. Request.getserverport () can return the port used by the server on which the current page is located, that is, Request.getcontextpath () can return the name of the application where the current page is located, which is the myblog in the example above. Four assembled together is the path to the current application.

Thanks to the http://www.cnblogs.com/token/archive/2012/08/13/2636287.html author for sharing

Java EE page Get path

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.