Java getServletContext().getRealPath(";)在WebLogic中返回null
当下面这行代码被执行时Java getServletContext().getRealPath(";)在WebLogic中返回null,java,jakarta-ee,servlets,weblogic12c,Java,Jakarta Ee,Servlets,Weblogic12c,当下面这行代码被执行时 String realPath = request.getSession().getServletContext().getRealPath(""); String imagePath = realPath/images/product/abc.jpeg; System.out.println("ImagePath-> " + imagePath) 当我试图打印sys out行时,我可以在weblogic中看到realPath返回null,如null/images
String realPath = request.getSession().getServletContext().getRealPath("");
String imagePath = realPath/images/product/abc.jpeg;
System.out.println("ImagePath-> " + imagePath)
当我试图打印sys out行时,我可以在weblogic中看到realPath返回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(文档ID 858783.1)
基于这一点,恐怕没有第三种选择。试试getRealPath(“/images/product/abc.jpeg”)。@EJP--谢谢。我想尝试一下不要劫持,但这是一个通用的解决方案吗?这对玻璃鱼有用吗?