I can't display images in JSP (and can't access other things like external Javascript/jQuery through SRC). The following JSP page just contains one <img>
tag that can not display the image located by the SRC.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="Temp.htm" method="post">
<img src="/images/temp.jpg" alt="Not available">
</form>
</body>
</html>
The images are in /WEB-INF/jsp/images
. I have also tried to change the image location and ensure all the times that the path given to SRC is correct still it didn't. The same is possible with the applications without the framework. It works there perfectly. What am I missing here?
First, /WEB-INF
is not accessible from the outside.
Second, if you use /images/temp.jpg
, the browser will load images from the root of the web server, and not from the root of your web-app (which is deployed under a context path).
Use the JSTL <c:url>
tag to generate absolute paths from the root of the web-app:
<img src="<c:url value='/images/temp.jpg'/>" alt=.../>
You cannot access files that are located in /WEB-INF/
directly from the web. The folder is protected from web access.
Locate your image files somewhere else. /images/temp.jpg
is a absolute path, however you likely need a relative one. Point your image path to image/temp.jpg
and place the images in the /images/
folder directly located under your web root. E.g. WebContent/images
or src/main/webapp/images
(depending on your web root).
Try put in the webapp directory, not WEB-INF. Obv. dont nest in the jsp dir.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With