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

标签 eclipse websphere-liberty open-liberty

我之前在本地环境下使用的是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/

相关文章:

JavaEE Websphere Liberty 没有根资源匹配请求且没有有效的 jdbcDriver

java - 在 Eclipse 中打开 Liberty : publishing results in an JMX connection error

Eclipse Luna SWT 版本

java - 信任 SSL 证书 : how does Commons HTTP client trust more than standard Java?

java - 无法访问浏览器异常

类路径位置的 logback.xml 文件未在自由配置文件服务器上获取

java - 在 IBM Websphere Libery Server 上运行 JPA EclipseLink 应用程序时出错

java - 无法在 WebSphere Liberty 配置文件中为多个应用程序配置 log4j

java - 使用 java eclipse 执行 Jython 脚本

java - Eclipse 中的 log4j.xml