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