Skip to content Skip to sidebar Skip to footer

Img Tag Image Not Loading In Chrome

I have been working on a dynamic web application and that requires to display a image on the jsp from my local files. Ant the program is running absolutely fine when I run it in ec

Solution 1:

You need to understand how the web works.

You have a user, located for example in France, using his browser to visit a web page at http://foo.bar.com. This sends an HTTP request to the server foo.bar.com located, for example, in Brazil. The server sends back an HTML page containing, for example

<imgsrc="image.jpg" />

When it sees this, the browser sends another HTTP request to the server in Brazil, asking for the image at http://foo.bar.com/image.jpg.

Note that everything the user sees in the browser comes from a web server, located elsewhere. A web site in Brazil is not authorized to open files on the user's machine in France. That would constitute a major security issue, since the web site could gather private information about the files on the end user's machine.

You're probably confused by the fact that, during development, the server and the client machine are the same one. But that doesn't change anything. Everything displayed on the web page of your app must come from the web server, over HTTP. You can't simply set the source of an image to a file path. The path of the image must point to an image served by your webapp, deployed in your web server.

Solution 2:

You need to put the image in your app to avoid problems when executing it in different locations:

<link rel="shortcut icon" href="<%=session.getAttribute("URL_HOST") %>/resources/your_image.jpg" />

To set the session attribute check this question

Post a Comment for "Img Tag Image Not Loading In Chrome"