简体   繁体   中英

Not able to create URL using getClass.getResource of an image in the web content folder

I have an image in web contents folder of path /images/car.bmp when i try to create URL of this image from a java class

URL url=getClass().getResource("/images/car.bmp");

i am getting null, why is that??

The directory structure is

Directory Structure

Because you are trying to load the resource from the class path and the image is not present on the class path.

If you want a URL for the image you want ServletConext#getResource(String path) where path is going to be /images/car.bmp .

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