Javaweb base 01--jsp to obtain absolute path application

Source: Internet
Author: User

1. Related function description

* Request.getscheme () waits for the protocol name, the default is http* Request.getservername () is the server name configured in the server's configuration file such as: localhost. baidu.com, etc. * Request.getserverport () Gets the port number configured in the server's configuration file, such as 8080, etc. * Request.getcontextpath ()  returns the root directory of the site * Request.getrealpath (" /") is the actual physical path, which is the path in the server where your project resides

2. Usage examples

<% StringBasePath= Request.getscheme ()+ "://" + request.getservername () + ":" + request.getserverport (); String Path= Request.getscheme ()+ "://" + request.getservername () + ":" + request.getserverport () + request.getcontextpath () + "    /"; String FilePath=path+ "resources/"; session.setattribute ("path", path);    Session.setattribute ("BasePath", BasePath); Session.setattribute ("FilePath", FilePath);>The project name for the above code is drp5.1, which can be found under Tomcat under the WebApp directory. where Request.getcontextpath () =/drp5.1basepath = Http://localhost:8080path = Http://localhost:8080/drp5.1/filePath = Http://localhost:8080/drp5.1/resources/

Javaweb base 01--jsp get absolute path application

Related Article

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.