I am using spring-mvc framework in my current project. ROOT folder has lots of web folders containing html, jsp, css, js etc. My spring mvc configuration is as follows:
Let’s say you have a directory (/resources/my_images/)
that contains some product images, and you want to serve these images upon request. For example, if the requested URL is http://localhost:8080/ mystore/resource/my_images/P123.png
, then you would like to serve the image with the P123.png
name. Similarly, if the requested URL is http://localhost:8080/mystore/resource/images/P1234.png
, then an image with the name P1234.png
needs to be served.
Now how you can serve static images with Spring MVC?
src/main/webapp/resources/my_images/
directory;DispatcherServlet-context.xml
file: <mvc:resources location="/resources/" mapping="/resource/**"/>
http://localhost:8080/mystore/resource/images/P123.png
(change the
image name in the URL based on the images you placed FYI: <mvc:resources>
tag in the web application context configuration to tell Spring where these image files are located in our project so that spring can serve those files upon request.