首页 > 代码库 > sessionScope整体的意思是获得存放在session.setAttrbute(key,value)的值
sessionScope整体的意思是获得存放在session.setAttrbute(key,value)的值
sessionScope整体的意思是获得存放在session.setAttrbute(key,value)的值
本文转载自熊佳佳《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>
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>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。