67,513
社区成员
发帖
与我相关
我的任务
分享
<form action="login">
用户名:<input type="text" name="userName"/><br/>
密 码:<input type ="text" name="password"/><br/>
<input type = "submit" value="登录" />
</form>
package rh;
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 {
if(getUsername().equals("scott")&&getPassword().equals("tiger")){
ActionContext.getContext().getSession().put("user", getUsername());
return SUCCESS;
}
else{
return ERROR;
}
}
}