NutzCN Logo
问答 【nutz book]【头像上传方法】req.getServletContext().getRealPath("/rs/user_avatar/none.jpg")报错
发布于 2801天前 作者 jacky013 2121 次浏览 复制 上一个帖子 下一个帖子
标签:

头像上传方法修改成如下才可以,是不是nutz book里写错了?
@Ok("raw:jpg")
@At("/avatar")
@GET
public Object readAvatar(@Attr(scope=Scope.SESSION, value="me")int userId, HttpServletRequest req) throws SQLException {
UserProfile profile = Daos.ext(dao, FieldFilter.create(UserProfile.class, "^avatar$")).fetch(UserProfile.class, userId);
if (profile == null || profile.getAvatar() == null) {
return new File(req.getSession().getServletContext().getRealPath("/rs/user_avatar/none.jpg"));
}
return profile.getAvatar().getBinaryStream();
}

1 回复

因为那是servlet 3.0的方法

req.getServletContext()

添加回复
请先登陆
回到顶部