我之前在本地环境下使用的是Tomcat v9.0,同时使用
getServletContext().getRealPath("")
检索路径,服务器返回
....metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\WebApp\
但是,当客户端运行 WebSphere Application Server Liberty 时,我在我的机器上安装了相同的代码,但返回 Tomcat 中路径的相同代码返回
null
在 Websphere 环境中。你能帮我理解为什么会发生这种情况以及我将如何在 Websphere 环境中获得路径。我也检查了以下链接 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("")
我不确定它是否适用于所有情况,但它在我的机器上运行良好。
关于eclipse - getServletContext().getRealPath ("") 在 WebSphere Application Server Liberty 中返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46430257/