我登录成功之后就存到session了
session.setAttribute("user_name",user.getSys_user_name());
然后我的过滤器是这么写的:
public View match(ActionContext actionContext) {
HttpServletRequest re = actionContext.getRequest();
HttpSession session = re.getSession();
String str = (String) re.getAttribute("user_name");
String user_id = (String) session.getAttribute("user_name");
if(user_id == null){
HttpServletResponse response = actionContext.getResponse();
try {
response.sendError(401,"您还没登录!");
return new VoidView();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
但是就是出现了用@Attr可以访问到的,但是过滤器里就是访问不到的情况,实在困惑...
@At
@Filters
public Object userInfo(@Attr("user_name")String user_name,HttpSession session){
String str = (String) session.getAttribute("user_name");
System.out.println(str);
User user = dao.fetch(User.class, Cnd.where(User.SYS_USER_NAME, "=", user_name));
if(user!=null){
return new NutMap().setv("code",1).setv("user",user);
}else{
return new NutMap().setv("code",0).setv("msg","未登录!");
}
}
这个里面可以获取到,但是过滤器里就获取不到