Reputation: 101
I'm trying to display image in my jsp from my local disk inside a web project. My Code is:
<img src="C:/Documents and Settings/chandhu/HelloWorld0.png" width="80px" height="100px" style="margin-left: 20px;"/>
After I run my application the image is not getting displayed. In src attribute it is additionally adding some source as mentioned below:
<img src="http://localhost:8080/Ecm/C:/Documents and Settings/chandhu/HelloWorld0.png" width="80px" height="100px" style="margin-left: 20px;"/>
Can anyone tell me what I am doing incorrectly?
Upvotes: 0
Views: 144
Reputation: 1290
You mentioned using jsp , therefor i think you are working with web application ,in your WEB-INF folder create a directory named image or as you needed and put your image there .
Now you can access that from code as :
String fullPath = servletContext.getRealPath("/WEB-INF/image/" + image_file_name+ ".jpg");
InputStream is = new FileInputStream(fullPath );
Or you may use :
InputStream stream = this.getClass().getResourceAsStream("/WEB-INF/image/image_file_name.jpg");
to read stream directly .
related question may help you :
JPEG file in WEB-INF returned as null by ServletContext#getResource()
Cant retrieve an images from the WEB-INF folder ussing classLoader.getResourceAsStream()
Upvotes: 0
Reputation: 2208
You can't do this way.. It should be in reach of container. or you can write a servlet which will read disk file and make HTTPResponse
Upvotes: 2