0

I do have simple JSP web page, but it's not displaying an image

This is my JSP page where it will fetch the image from pics folder under web content

<%@ page language="java" contentType="text/html; charset=UTF-8"
    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>Insert title here</title>
  </head>
  <body>

     <img width = "80" src="${pageContext.request.contextPath}/pics/">
  </body>
</html>

But the page looks like this

enter image description here

Satendra
  • 6,755
  • 4
  • 26
  • 46
Karamzov
  • 343
  • 1
  • 4
  • 12

2 Answers2

0

First Try an output with ${pageContext.request.contextPath}: make sure its where you expect the /pics/ folder to be

Next de path should mapped correctly: for example in de context.xml in tomcat

<Context path="/media/pics" docBase="C:/data/pics" debug="0" privileged="true">
</Context>

Extra tip: Have a look at Mapping a directory outside the web-app to URL in TOMCAT

Always have your media files separated outside your tomcat folder

Rey333
  • 350
  • 2
  • 12
0

Your code should somewhat be like

<img width = "80%" src="${pageContext.request.contextPath}/pics/imagename.jpg">

File name is necessary and change 80 to 80% because your image might be too big and might just display a part of it

Also make sure

${pageContext.request.contextPath}

is not empty

And to be absolutely sure

<img width = "80%" src="check_with_original_directory/pics/imagename.jpg">
kowsikbabu
  • 499
  • 1
  • 6
  • 23