[英]getServletContext().getRealPath(“”) returning null In WebLogic
When the below line it got executed 当下面的行被执行时
String realPath = request.getSession().getServletContext().getRealPath("");
String imagePath = realPath/images/product/abc.jpeg;
System.out.println("ImagePath-> " + imagePath)
When I trying to print the sys out line, I can see the realPath returning null in weblogic as null/images/product/abc.jpeg
当我尝试打印sys out行时,我可以看到realPath在weblogic中返回null为null/images/product/abc.jpeg
When I google for the solution. 当我谷歌寻求解决方案。 There are two solution I found:- 我找到了两个解决方案: -
1.By manually I can go to Weblogic Console -> Domains -> Web Application -> Check the archived real path (which I dont want to do) 1.通过手动我可以进入Weblogic控制台 - >域 - > Web应用程序 - >检查存档的真实路径(我不想这样做)
2.I can add the below entry into weblogic.xml manually 2.我可以手动将以下条目添加到weblogic.xml中
<container-descriptor>
<show-archived-real-path-enabled>true</show-archived-real-path-enabled>
</container-descriptor>
which I added in weblogic.xml
and tried to redeploy but still realPath is returning null after adding in xml files. 我在weblogic.xml
添加并尝试重新部署但仍然在添加xml文件后,realPath返回null。
As soon as I am trying the first approach by changing the settings in console , then I can see realPath is returning proper path.But which I don't wan't that user should do any changes. 一旦我通过更改控制台中的设置尝试第一种方法,那么我可以看到realPath正在返回正确的路径。但是我不认为该用户应该做任何更改。
Is any other alternate way apart from the above two for weblogic or may be I am missing something. 对于weblogic,是否有任何其他替代方式与上述两种方式不同,或者可能是我遗漏了某些东西。
It worked for me on WLS12.1.3 using your second option. 它使用您的第二个选项在WLS12.1.3上为我工作。 Both methods are documented by Oracle: Invoking ServletContext.getRealPath() in archived web applications throws NullPointerException (Doc ID 858783.1) Oracle记录了这两种方法: 在归档的Web应用程序中调用ServletContext.getRealPath()会抛出NullPointerException(Doc ID 858783.1)
Based on that note, I am afraid there is no 3rd option. 根据这一说明,我恐怕没有第三种选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.