String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () effect

Source: Internet
Author: User

Q: There are statements like this
:
String Path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
<base href= "<%=basePath%>" >


Answer: 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, and 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, then 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, which is "http" in the example above
Request.getservername () 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,
Request.getcontextpath () can return the name of the application in which the current page is located, which is the myblog in the example above
These four assembled, is the current application of the follow-up path

String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () effect

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.