getServletContext().getRealPath("") 在 WebSphere Application Server Liberty 中返回 null

getServletContext().getRealPath("") returning null in WebSphere Application Server Liberty

我之前在本地环境中使用 Tomcat v9.0,而使用

getServletContext().getRealPath("")

检索路径,服务器返回

....metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\WebApp\

然而,当客户端运行 WebSphere Application Server Liberty 时,我在我的机器上安装了相同的,但相同的代码 returns Tomcat、returns

中的路径

null

在 Websphere 环境中。你能帮我理解为什么会发生这种情况以及我将如何获得 Websphere 环境中的路径。我还检查了以下 link https://www.ibm.com/developerworks/community/forums/html/topic?id=eb04c8ae-02d4-421b-af2c-2ef626a3db1b&ps=50&tags=&query=&filter=&sortBy=&order=asc,但找不到解决方案。

我确实得到了Websphere环境中的路径。在 Websphere 中,要求我们必须给出一个 '/' 而不是空字符串,即

getServletContext().getRealPath("/")

而不是

getServletContext().getRealPath("")

我不确定它是否适用于所有情况,但它在我的机器上运行良好。