码迷,mamicode.com
首页 > 其他好文 > 详细

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

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

标签:style   blog   class   tar   ext   color   

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)的值

标签:style   blog   class   tar   ext   color   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!