当下面的行被执行时
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 - >域名 - >网络应用程序 - >检查存档的真实路径
(我不想这样做)
2.我可以手动将以下条目添加到weblogic.xml中
<container-descriptor>
<show-archived-real-path-enabled>true</show-archived-real-path-enabled>
</container-descriptor>
我在weblogic.xml
中添加并尝试重新部署,但在添加xml文件后,realPath仍返回null。
当我通过更改控制台中的设置尝试第一种方法时,我可以看到realPath正在返回正确的路径。但是,我不希望该用户做任何更改。< / p>
对于weblogic,除了以上两种方式之外是否有其他替代方式,或者可能是我遗漏了某些内容。
答案 0 :(得分:0)
使用您的第二个选项在WLS12.1.3上为我工作。 Oracle记录了这两种方法: 在归档的Web应用程序中调用ServletContext.getRealPath()会抛出NullPointerException(Doc ID 858783.1)
根据该说明,我恐怕没有第三种选择。