getRealPath
java.lang.String getRealPath(java.lang.String path)
Gets the real path corresponding to the given virtual path.
For example, if path is equal to /index.html, this method will return the absolute file path on the server's filesystem to which a request of the form http://<host>:<port&... would be mapped, where <contextPath> corresponds to the context path of this ServletContext.
上面是API的解释,我疑惑的是这个virtual path。
一般的用法是serveletContext.getRealPath(“/”),“/”可以理解为,应用的根目录,那么“” 呢?
希望有大神能,详细的解释这个virtual path的概念。
======To answer your question, I suddenly encountered a segmentfault and the website crashed. I wrote the answer again====
is an interface. The specific implementation is implemented by a servlet container, such as tomcat. A method called getRealPath is defined in this interface, and the corresponding implementation is also implemented by various servlet containers. I didn't check the source code of tomcat, only the mock implementation of spring.
In this implementation, you can see that the effect of passing "" and "/" is the same. There is no need to explain more since the code is already there. The implementation of other containers is estimated to be similar.