我在UserAction中这样写的
public String execute() throws Exception {
if (userService.isLogin(user)) {
ActionContext context = ActionContext.getContext();
Map<String, User> session = context.getSession();
session.put("user", user);
System.out.println("判断ACTION已经执行");
return this.SUCCESS;
}
else
return this.LOGIN;
}
在拦截器中
public String intercept(ActionInvocation invocation) throws Exception {
// TODO Auto-generated method stub
System.out.println("ssssssssssssssssssssss");
// 对LoginAction不做该项拦截
Object action = invocation.getAction();
if (action instanceof UserAction) {
System.out.println("exit check login, because this is login action.");
return invocation.invoke();
}
// 确认Session中是否存在LOGIN
Map session = invocation.getInvocationContext().getSession();
String user = (String) session.get("user");
if(user!=null&&user.length()>0){
// 存在的情况下进行后续操作。
System.out.println("already login!");
return invocation.invoke();
}else{
// 否则终止后续操作,返回LOGIN
System.out.println("no login, forward login page!");
return Action.LOGIN;
}
配置也已经完善好了,但是在进行登录的时候String user = (String) session.get("user");在这行 报错~我在Action中将从数据库中获取username和password内容 放在了 user中了~为什么 会报错?