繁体   English   中英

getServletContext()。getRealPath(“”)返回null在WebLogic中

[英]getServletContext().getRealPath(“”) returning null In WebLogic

当下面的行被执行时

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控制台 - >域 - > Web应用程序 - >检查存档的真实路径(我不想这样做)
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,是否有任何其他替代方式与上述两种方式不同,或者可能是我遗漏了某些东西。

它使用您的第二个选项在WLS12.1.3上为我工作。 Oracle记录了这两种方法: 在归档的Web应用程序中调用ServletContext.getRealPath()会抛出NullPointerException(Doc ID 858783.1)

根据这一说明,我恐怕没有第三种选择。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM