【问题标题】:getServletContext().getRealPath("") returning null In WebLogicgetServletContext().getRealPath("") 在 WebLogic 中返回 null
【发布时间】:2014-11-21 07:30:52
【问题描述】:

当下面一行被执行时

String realPath = request.getSession().getServletContext().getRealPath("");
String imagePath = realPath/images/product/abc.jpeg;
System.out.println("ImagePath-> " + imagePath)

当我尝试打印 sys out 行时,我可以看到 realPath 在 weblogic 中返回 null 为 null/images/product/abc.jpeg

当我用谷歌搜索解决方案时。我找到了两个解决方案:-
1.通过手动我可以去Weblogic Console -> Domains -> Web Application -> Check the archived real path (我不想这样做)
2.我可以手动将以下条目添加到weblogic.xml中

   <container-descriptor>
        <show-archived-real-path-enabled>true</show-archived-real-path-enabled>
    </container-descriptor>

我在weblogic.xml 中添加并尝试重新部署,但在添加 xml 文件后,realPath 仍然返回 null。

当我通过更改控制台中的设置尝试第一种方法时,我可以看到 realPath 正在返回正确的路径。但我不希望该用户应该做任何更改。

除了以上两种用于 weblogic 之外,还有其他替代方式吗,或者我可能遗漏了什么。

【问题讨论】:

  • 试试 getRealPath("/images/product/abc.jpeg")。
  • @EJP-- 谢谢..我试试看
  • 不要劫持,但这是一个通用的解决方案吗?这对 glassfish 有用吗?

标签: java jakarta-ee servlets weblogic12c


【解决方案1】:

使用您的第二个选项,它在 WLS12.1.3 上对我有用。 Oracle 记录了这两种方法: 在存档的 Web 应用程序中调用 ServletContext.getRealPath() 会引发 NullPointerException(文档 ID 858783.1)

根据那个说明,恐怕没有第三种选择。

【讨论】:

    猜你喜欢
    • 2010-11-29
    • 1970-01-01
    • 1970-01-01
    • 2015-04-08
    • 2020-07-31
    • 1970-01-01
    • 2013-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多