简体   繁体   中英

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

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)
2.I can add the below entry into weblogic.xml manually

   <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.

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.

Is any other alternate way apart from the above two for weblogic or may be I am missing something.

It worked for me on WLS12.1.3 using your second option. Both methods are documented by Oracle: Invoking ServletContext.getRealPath() in archived web applications throws NullPointerException (Doc ID 858783.1)

Based on that note, I am afraid there is no 3rd option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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