当前位置:编程学习 > JAVA >>

求助:ActionContext.getContext().put("user",getUsername())前台JSP获取不到值

这是loginAction代码:
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;
}

public String check(){
if(getUsername().equals("scott")&&getPassword().equals("tiger")){
System.err.println(username);
ActionContext.getContext().put("user",username);
return SUCCESS;
}
else{
return LOGIN;
}
}
}
//=================================================================
这是JSP页面代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>welcome</title>
</head>
<body>
welcome,${sessionScope.user}!
<form action="showBooks.action" method="post">
<input type="submit" value="show books">
</form>
</body>
</html>
//===========================================================================
问题就是:在JSP页面中获取不到user的值,编译不报错,求助!! --------------------编程问答-------------------- 自己先顶一下,求助大神们啊 --------------------编程问答-------------------- 我去啊!!!!!太粗心了
ActionContext.getContext().put("user",username);这句少了一部分,正确的是ActionContext.getContext().getSession().put("user",username);
细心!一定要细心!
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,