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"/>取不到值啊??
高手指点下

解决方案 »

  1.   

    既然放到session里面了,直接session.getAttribute()就可以了.
      

  2.   


    <s:property value="#session.currentUser.userName"/>
    是不是你的名字写错了!
      

  3.   

    currentUser.usName  user有usName这个属性吗.?  
    好像是名字搞错了
      

  4.   

    #session.currentUser.usName 改为 #session.currentUser.userName 
      

  5.   

    currentUser.usName user有usName这个属性吗.?   
    好像是名字搞错了
      

  6.   

    currentUser.usName user有usName这个属性吗.?   
    好像是名字搞错了
      

  7.   

    userName 是action里面的变量
    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;
    }
      

  8.   

    检查下userService.Login(this.getUserName(), this.getUserPwd())是否取到值了??
      

  9.   

    虽然sttruts的精髓在于标签,但是现在越来越多的情况下不要使用标签。
    建议楼主直接是用:
    session.getAttrbiute("currentUser");
      

  10.   

    struts2? 写个<debug>标签 看看里面有没有就知道了
      

  11.   

    没有get方法怎么取值,session只是一个变量