【问题标题】:Why does the same code work in a servlet but not in a Spring controller?为什么相同的代码在 servlet 中有效,而在 Spring 控制器中无效?
【发布时间】:2011-02-18 16:18:15
【问题描述】:

此代码在 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);
}

所以我尝试使用model.addAttribute(下)而不是req.setAttribute(上)将它放入Spring控制器:

PicasawebService service = new PicasawebService("Picasa test");
PicasawebClient picasaClient = new PicasawebClient(service);
List<AlbumEntry> albums = picasaClient.getAlbums("cgcmh1@gmail.com");
for (AlbumEntry album : albums){
    logger.warn("albums:" + album.getTitle().getPlainText());
    List<PhotoEntry> photos = picasaClient.getPhotos(album);
    model.addAttribute("photos", photos);
}

但是,Spring 代码无法在 Picasa 中找到任何相册,而 servlet 代码可以成功找到它们。

有人知道为什么会这样吗?

在这两种情况下,他们都使用this version of the PicasawebClientthis version of the PicasawebService

【问题讨论】:

  • 你的 JSP 是什么样的?你的 Spring 配置是什么样的?

标签: java spring spring-mvc gdata picasa


【解决方案1】:
model.addAttribute("photos", photos);

将在每次迭代时覆盖地图的photos 属性,因此您将只能访问最后一张专辑。

【讨论】:

    猜你喜欢
    • 2019-09-21
    • 1970-01-01
    • 2011-05-25
    • 1970-01-01
    • 2018-11-14
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    • 2019-04-16
    相关资源
    最近更新 更多