The role of BasePath

Source: Internet
Author: User

 the role of BasePathCategory: Java technology 2013-03-03 14:30 4492 people read reviews (0) favorite reports the role of BasePath

2012-11-25 23:16:41 |   Category:  j2ee |   Tags: jsp    | font size   subscription

  Before we talk about BasePath, let's discuss the difference between the relative path and the absolute path.    relative path-The directory path that is established as a reference based on the location of the page where the file is referenced.   Absolute path-the directory path based on the Web site root directory.    the absolute path in the Web application does not refer to the disk file in the character directory path. such as:c:\windows\system32  in fact, the absolute path and the relative path is different, only in the description of the directory path, the reference point is different. Because the reference point of the root directory is the same for all files on the site, the path description using the root directory as the reference point is called an absolute path.   Here need to speak a few special symbols:  "/" stands for the root directory, "..." Represents a previous level of directory, while the ".. /.. /"represents the previous level of the previous directory. Suppose you register the domain name www.arm4u.com, and apply for a virtual host, your virtual hosting provider to you a directory, such as WWW, this www is the root directory of your site.    Suppose you have a file index.html in the WWW root directory, the absolute path to this file is: http://www.arm4u.com/index.html.    Suppose you build a directory under the WWW root directory called html_tutorials, and then drop a file in that directory index.html, the absolute path to the file is Http://www.arm4u.com/html_ tutorials/index.html   understand the concept of relative path and absolute road strength, let's see how the so-called BasePath is written:  <%string path = Request.getcontextpath (); String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%>   Look at the code above, let's see what it means,  request.getcontextpath () is a frequently used method in developing Web projects, which is to get the current system path. Request.getcontextpath () Gets the project name, if the item is the root directory, then gets a "", that is, the empty note string, if the item is test, <%=request.getcontextpath ()% >/will get test/, and the server-side path will be automatically added.   request.getscheme () returns the protocol name, which is HTTP by default.  request.getservername () returns the hostname (example 127.0.0.1) displayed in your browser.  getserverport () Gets the server port number (example: 8080).   We may as well print out the basepath to see what it is, http://127.0.0.1:8080/test.    It's worth noting that request.getservername () always gets the host name shown in the browser, for example, We are browsing in which the host name entered is the local hostname 192.168.10.23, then we can access the project through http://192.168.10.23:8080/test this path in the intranet, if the external network needs access to provide the domain name HTTP// Www.arm4u.com/Test to access, of course, the intranet can also be accessed through this path, at this time the print out of the basepath is the path http://www.arm4u.com:8080/Test, rather than HTTP/ 192.168.10.23:8080/test <base href= "<%=basePath%>" > must be placed in

The role of BasePath

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.