在一个action类中有这个代码:ActionContext.getContext().getSession().put("user", getUsername());在一个跳转到的JSP页面中:欢迎 ${sessionScope.user}可是当我转到这个页面后,显示的不是“欢迎XXX”,而是“欢迎 ${sessionScope.user}”请问这是什么问题我用的是struts2的状态跟踪!!

解决方案 »

  1.   

    Action:public class LoginAction implements Action 
    {
    private String username;
    private String password;
            ……………………get & set
    public String execute() throws Exception {
    // TODO Auto-generated method stub
    if(getUsername().equals("scott") && getPassword().equals("tiger"))
    {
    ActionContext.getContext().getSession().put("user",getUsername());
    return SUCCESS;
    }
    else
    {
    return ERROR;
    }
    }
      

  2.   

    jsp页面:<body>
        您已经成功登陆!!欢迎 ${sessionScope.user}
    </body>
      

  3.   

    你获得session后你用setAttribute("", );来做看看!