Search code examples
javaimagejspspring-mvcjakarta-ee

How to display a image in jsp, which is located in root directory of server


I am new to spring MVC and I have a application which store images in the root directory of the application.

The directory is something this like this : C:\Users\Golla\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\medicalus\images\1423310234176.png

My Project's name is medicalus and the images folder is used to save images. Now I want to retrieve it and display it in the jsp page. I have tried giving up the complete path of images and tried adding in < mvc:resources> tag of servlet dispatcher but none of these worked.

How can I display images which are located in the root directory of the server? Any suggestion would be appreciated.


Solution

  • Try this:

    1. In the Spring's configuration file:

      <mvc:resources mapping="/images/**" location="/images/" />
      
    2. In you JSP:

      <img src="${pageContext.request.contextPath}/images/1423310234176.png" />