i'm writing my first webapp in Spring MVC. It's dynamic web page, where user can add wallpaper by multipart/form-data
. Then he's redirected to home page, where are displayed all of added pictures. But when i'm trying to add image and see the result i can see only empty div
, like pictures would not exist. But after restarting Tomcat image is displaying properly. I tried to change a scope
, but it was bad idea I think. Also i changed LinkedList
to ArrayList
, also unsuccessfully.
home.jsp
<div class="row">
<c:forEach items="${paths}" var="path">
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="#">
<img class="img-responsive" src="../../../resources/wallpapers/${path}">
</a>
</div>
</c:forEach>
</div>
WallpaperService.java
public List<Wallpaper> wallpapers = new LinkedList<>();
public List<String> paths = new ArrayList<>();
public Wallpaper addWallpaper(File image) {
Wallpaper wallpaper = new Wallpaper();
wallpaper.setImage(image);
wallpapers.clear();
wallpapers.add(wallpaper);
return wallpaper;
HomeController.java
File[] files = new File("D:\\IntelliJ IDEA\\Wallpapers\\src\\main\\web\\resources\\wallpapers\\").listFiles();
@RequestMapping("/")
public String home(Model model){
wallpaperService.paths.clear();
for (File file : files) {
wallpaperService.paths.add(file.getName());
}
model.addAttribute("paths", wallpaperService.paths);
return "home";
}
img: home view
generated html(first div with image is not displaying, another one was added earlier, displayed properly after restarted tomcat):
<div class="row">
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="/resources/wallpapers/wallhaven-138570.jpg"
data-lightbox="wallhaven-138570.jpg">
<img class="img-responsive" src="/resources/wallpapers/wallhaven-138570.jpg" />
</a>
</div>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="/resources/wallpapers/wallhaven-29611.jpg"
data-lightbox="wallhaven-29611.jpg">
<img class="img-responsive" src="/resources/wallpapers/wallhaven-29611.jpg" />
</a>
</div>
</div>