1

I have stored the image in a folder and saved the path in mySql database. When i try to display the image in jsp page, image is not getting displayed. But when i try to print the path i can see the path getting displayed. Not sure where i am going wrong, can someone help me..

Servlet:

HttpSession session = request.getSession();
List sname = new ArrayList();
List photo1 = new ArrayList();
DAO dao = new DAO();
for(Newsfeed nfc: dao.display()) // dao.display() - Hibernate DAO
 {
      sname.add(nfc.getUsername());
      photo1.add(nfc.getPhoto());
 }
 session.setAttribute("photo1", photo1);
 session.setAttribute("sname", sname);
 RequestDispatcher rd=request.getRequestDispatcher("/upload.jsp");
 rd.forward(request, response);

JSP Page:

  <% List sname = (List) session.getAttribute("sname");
  List photo1 = (List) session.getAttribute("photo1"); %>
  <c:forEach items="${photo1}" var="pic">
  <img src="<c:url value="${pic}"/>"/>  <br>
  </c:forEach>

But instead if i try to display the path name, its working

 <c:forEach items="${photo1}" var="pic">
  ${pic} <br>
  </c:forEach>

if i run this, i get the output

E:/upload/thres.gif
E:/upload/audio.png

Not sure how to display this as an image...

JavaLearner1
  • 607
  • 2
  • 8
  • 21

1 Answers1

0

The path is the local file path. Visitors will not be able to fetch that from the website. You will need to put it to a publicly accessible folder of a web server and use that link.

Tuan Anh Tran
  • 6,807
  • 6
  • 37
  • 54