public class BaseAction extends ActionSupport implements SessionAware {
private Map session;public void setSession(Map session) {
this.session = session;
}
}public class LoginAction extends BaseAction {private UserSerivce userService;
private String userName;
private String userPwd;public String getUserName() {
return userName;
}public void setUserName(String userName) {
this.userName = userName;
}public String getUserPwd() {
return userPwd;
}public void setUserPwd(String userPwd) {
this.userPwd = userPwd;
}public void setUserService(UserSerivce userService) {
this.userService = userService;
}public String Login() {
Personal user = null;
try {
user = userService.Login(this.getUserName(), this.getUserPwd());
Map session = new HashMap<String, Object>();
session.put("currentUser", user);
super.setSession(session);
} catch (Exception ex) {
ex.printStackTrace();
return ERROR;
}
if (user != null) { // 成功登录
return SUCCESS;
}
return LOGIN;
}}页面:
<s:property value="#session.currentUser.usName"/>取不到值啊??
高手指点下
private Map session;public void setSession(Map session) {
this.session = session;
}
}public class LoginAction extends BaseAction {private UserSerivce userService;
private String userName;
private String userPwd;public String getUserName() {
return userName;
}public void setUserName(String userName) {
this.userName = userName;
}public String getUserPwd() {
return userPwd;
}public void setUserPwd(String userPwd) {
this.userPwd = userPwd;
}public void setUserService(UserSerivce userService) {
this.userService = userService;
}public String Login() {
Personal user = null;
try {
user = userService.Login(this.getUserName(), this.getUserPwd());
Map session = new HashMap<String, Object>();
session.put("currentUser", user);
super.setSession(session);
} catch (Exception ex) {
ex.printStackTrace();
return ERROR;
}
if (user != null) { // 成功登录
return SUCCESS;
}
return LOGIN;
}}页面:
<s:property value="#session.currentUser.usName"/>取不到值啊??
高手指点下
<s:property value="#session.currentUser.userName"/>
是不是你的名字写错了!
好像是名字搞错了
好像是名字搞错了
好像是名字搞错了
usName是Personal类里面的属性,大家看这句Personal user = null;
try {
user = userService.Login(this.getUserName(), this.getUserPwd());
Map session = new HashMap<String, Object>();
session.put("currentUser", user);
super.setSession(session);
} catch (Exception ex) {
ex.printStackTrace();
return ERROR;
}
建议楼主直接是用:
session.getAttrbiute("currentUser");