dao:
@Override
public int userLogin(User user) {
String hql = "from User where username = '" + user.getUsername()
+ "' and password = '" + user.getPassword() + "'";
Query query = sessionFactory.getCurrentSession().createQuery(hql);
int i = query.list().size();
return i;
}
action:
@Action(value = "/userLogin", results = {
@Result(name = SUCCESS, location = "/index.jsp"),
@Result(name = ERROR, location = "/error.jsp") })
public String login() {
if (userService.login(user)) {
ActionContext ac = ActionContext.getContext();
ac.getSession().put("user", user);
System.out.println("action user:" + user.getUserid()); //输出为null
return SUCCESS;
}
return ERROR;
}