如果没登录,我想响应一个401状态码,这么写可以码?还是return nutz提供的?
@Filters
public class CheckSession implements ActionFilter {
public View match(ActionContext actionContext) {
HttpServletRequest re = actionContext.getRequest();
Integer user_id = (Integer) re.getSession().getAttribute("user_id");
if(user_id == null){
HttpServletResponse response = actionContext.getResponse();
try {
response.sendError(401,"您还没登录!");
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}