67,538
社区成员
发帖
与我相关
我的任务
分享public class LoginAction implements Action
{
//下面是Action内用于封装用户请求参数的两个属性
private String username;
private String password;
//username属性对应的getter方法
public String getUsername()
{
return username;
}
//username属性对应的setter方法
public void setUsername(String username)
{
this.username = username;
}
//password属性对应的getter方法
public String getPassword()
{
return password;
}
//password属性对应的setter方法
public void setPassword(String password)
{
this.password = password;
}
//处理用户请求的execute方法
public String execute() throws Exception
{
//当用户请求参数的username等于scott,密码请求参数为tiger时,返回success字符串
//否则返回error的字符串
if (getUsername().equals("scott")
&& getPassword().equals("tiger") )
{
ActionContext.getContext().getSession().put("user",getUsername()) ;
return SUCCESS;
}
else
{
return ERROR;
}
}
}