Servlet: what exactly is used context.getRealPath ("");

How do I know it returns the application path? But what exactly is it to use.

+5
source share
4 answers

In many environments, the application user is not allowed to read files outside the deployment directory. This is mainly done for security - for example, if someone breaks into your application, he will not be able to read the password file.

And in professionally managed environments, developers often do not have voting rights in the directory in which the application will be hosted.

, , , , .., ( .war ) getRealPath (""), , .

, . , .

+5

GetRealPath() ( ), , . , . getContextPath() URI .

+2

, , , . , Eclipse Tomcat , Eclipse .

+1

.

javadoc:

, , , . null, - (, .war).

I think this is very clear. Why do we need this? Sometimes web applications do some manipulation of the file system. For example, read material from files, write files, etc. This API allows you to access where your JSP and other things are really stored.

+1
source

All Articles