开发者

Why does the same code work in a servlet but not in a Spring controller?

开发者 https://www.devze.com 2023-02-11 08:23 出处:网络
This code works in a servlet: PicasawebService service = new PicasawebService(\"Picasa test\"); PicasawebClient picasaClient = new PicasawebClient(service);

This code works in a servlet:

PicasawebService service = new PicasawebService("Picasa test");
PicasawebClient picasaClient = new PicasawebClient(service);
List<AlbumEntry> albums = picasaClient.getAlbums("cgcmh1@gmail.com");
for(AlbumEntry album: albums){
    resp.getWriter().println(album.getTitle().getPlainText());
    List<PhotoEntry> photos = picasaClient.getPhotos(album);
    req.setAttribute("photos", photos);
}

So I tried putting it in a Spring controller by using model.addAttribute (below) instead of req.setAttribute (above):

PicasawebService service = new PicasawebService("Picasa test");
PicasawebClient picasaClient = new PicasawebClient(service);
List<AlbumEntry> albums = picasaClient.getAlbums("cgcmh1@gmail.com");
for (AlbumEntry album : albums){
    log开发者_如何学编程ger.warn("albums:" + album.getTitle().getPlainText());
    List<PhotoEntry> photos = picasaClient.getPhotos(album);
    model.addAttribute("photos", photos);
}

However, the Spring code fails to find any albums in Picasa while the servlet code finds them successfully.

Anyone know why this is the case?

In both cases they are using this version of the PicasawebClient and this version of the PicasawebService.


model.addAttribute("photos", photos);

will override the photos attribute of the map on each iteration, so you will only be able to access the last album.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号