0

I'm new in web development (spring-mvc), my background is from android world. I'm receiving images from service every 2 second, than I'm saving them to the WEB-INF/images folder, at this time every 1 second, I'm making ajax request to retrieve and display received image. This is how I'm making ajax call

function updateImage() {
    $.get('/api/getCurrentImagePath/', function (frameImagePath) {
        $("#targetImgView").attr("src", frameImagePath);
        setTimeout(updateImage, 1000)
    })
}

My problem is that, when function is invoked $("#targetImgView").attr("src", frameImagePath); console logs http://localhost:8080/images/13456482154.jpg 404 not found error but received image path is correct.

How can I resolve this issue? or is there any better way to do, what I'm trying to do?

P.S

when I save images into the webapp/images folder during the running server and trying to set the path of images it does not works, but if I restart the server and statically set the path of already saved images it works

Jemo Mgebrishvili
  • 5,187
  • 7
  • 38
  • 63

1 Answers1

0

In Spring MVC, we have to options to display images

  1. From another FTP server
  2. From within EAR, to do so you can open images placed inside resource folder

Add this entry in dispatcher-servlet.xml

<mvc:resources mapping="/image/**" location="/resources/images/" cache-period="0"/>

You need to put images in your webapp/resources/images folder. After that access the image contextPath/image/imageName.jpg

jeet427
  • 538
  • 3
  • 16
  • what is the difference? now I'm saving images to the webapp/images/ dir – Jemo Mgebrishvili Feb 05 '18 at 12:05
  • the difference is `resources mapping` tells spring to map the urls of images. you may [see this](https://stackoverflow.com/questions/8195213/spring-3-mvc-resources-and-tag-mvcresources) for more info – jeet427 Feb 06 '18 at 03:44
  • when I save images into the webapp/images folder during the running server it doesnot works, but if I restart the server and statically set the path of images which were saved already it works – Jemo Mgebrishvili Feb 06 '18 at 07:31