Search code examples
jspjakarta-eeservletsjsp-tags

Display Image using <img> tag and JSP scriptlet?


I am trying to display the image on JSP page using Following code

<% String url;
        url=config.getServletContext().getRealPath("/images/1.jpg"); %>
        <img src= <%=url%>/>

I also try to give double-quot but it does not work can anyone tell me can i give absolute path to the image file like this or i have to use the streams for it ?

And which is the best way to store images and uploaded file relative path or absolute path or into the database ?


Solution

  • To display the image within the html you must give a relative path to the root of the webpage.