簡體   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