首页 > 其他 > 详细

sessionScope整体的意思是获得存放在session.setAttrbute(key,value)的值

时间:2014-05-04 10:21:04      阅读:392      评论:0      收藏:0      [点我收藏+]

sessionScope整体的意思是获得存放在session.setAttrbute(key,value)的值  

 
package com.demo.struts2;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;


public class LoginAction extends ActionSupport {

    private String username;
    private String password;
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    @Override
    public String execute() throws Exception {
        // TODO Auto-generated method stub
        if(getUsername().equals("admin")&&getPassword().equals("admin")){
            ActionContext.getContext().getSession().put("user", getUsername());
            return SUCCESS;
        }else{
            return ERROR;
        }
    }
    
}
--------------------------------------------------------------------------------------------
<%@ taglib prefix="s" uri="/struts-tags" %>
<body>
      <s:text name="succTip">
          <s:param>${sessionScope.user}</s:param>
      </s:text>
  </body>
========================================================
package com.demo.struts2;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;


public class LoginAction extends ActionSupport {

    private String username;
    private String password;
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    @Override
    public String execute() throws Exception {
        // TODO Auto-generated method stub
            ActionContext ctx=ActionContext.getContext();
            Integer counter=(Integer)ctx.getApplication().get("counter");
            if(counter==null){
                counter=1;
            }else{
                counter=counter+1;
            }
        
    ctx.getApplication().put("counter", counter);
            ctx.getSession().put("user", getUsername());
            if(getUsername().equals("root")&&getPassword().equals("admin")){
                ctx.put("tip", "服务器提示:您已经成功登陆");
                return SUCCESS;
            }else{
                ctx.put("tip", "服务器提示:登陆失败");
                return ERROR;
            }

    
    }
    
}
--------------------------------------------------------------------------------------------
<%@ taglib prefix="s" uri="/struts-tags" %>
  <body>
本站访问次数:${applicationScope.counter}<br> 
${sessionScope.user }您已经登陆<br>
${request.tip }
<br>
  </body>

sessionScope整体的意思是获得存放在session.setAttrbute(key,value)的值,布布扣,bubuko.com

sessionScope整体的意思是获得存放在session.setAttrbute(key,value)的值

原文:http://www.cnblogs.com/aofavx/p/3705715.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!