login.jsp的代码:
<form name=theForm method=post action="login.action">
<TABLE cellSpacing=1 cellPadding=3 width=100% border=0>
<caption>
QA登陆测试系统
</caption>
<TBODY>
<tr>
<td bgColor=#F5F5F5 colspan=2 id=ttdd>
<s:actionmessage/>
</td>
</tr>
<TR>
<TD bgColor=#F5F5F5 width="70px">
用户名
</TD>
<TD bgColor=#F5F5F5>
<INPUT id=username type=text name=username>
</TD>
</TR>
<TR>
<TD bgColor=#F5F5F5>
密码
</TD>
<TD bgColor=#F5F5F5>
<INPUT id=password type=password size=21 name=password>
</TD>
</TR>
<TR>
<TD bgColor=#F5F5F5>
验证码
</TD>
<TD bgColor=#F5F5F5>
<INPUT id=check type=text size=10 name=check>
<img src="test/random" id="checkimg" alt="随机图片"
title="验证图片" />
<a href="#" onClick="refresh()">看不清?</a>
</TD>
</TR>
<TR>
<TD bgColor=#F5F5F5 colspan=2 align=center>
<input type=submit value=登陆
onclick="return clientValidate()" class=btn3_mouseout
onmouseover="this.className='btn3_mouseover'"
onmouseout="this.className='btn3_mouseout'"
onmousedown="this.className='btn3_mousedown'">
<input type="button" value="注册"
onclick="javascript:window.location.href='regist2.jsp'"
class=btn3_mouseout
onmouseover="this.className='btn3_mouseover'"
onmouseout="this.className='btn3_mouseout'"
onmousedown="this.className='btn3_mousedown'">
<input type=button value=忘记密码
onclick="javascript:window.location.href='passforget.jsp'"
class=btn3_mouseout
onmouseover="this.className='btn3_mouseover'"
onmouseout="this.className='btn3_mouseout'"
onmousedown="this.className='btn3_mousedown'"> </TD>
</TR>
</TBODY>
</TABLE>
</form>
<form name=theForm method=post action="login.action">
<TABLE cellSpacing=1 cellPadding=3 width=100% border=0>
<caption>
QA登陆测试系统
</caption>
<TBODY>
<tr>
<td bgColor=#F5F5F5 colspan=2 id=ttdd>
<s:actionmessage/>
</td>
</tr>
<TR>
<TD bgColor=#F5F5F5 width="70px">
用户名
</TD>
<TD bgColor=#F5F5F5>
<INPUT id=username type=text name=username>
</TD>
</TR>
<TR>
<TD bgColor=#F5F5F5>
密码
</TD>
<TD bgColor=#F5F5F5>
<INPUT id=password type=password size=21 name=password>
</TD>
</TR>
<TR>
<TD bgColor=#F5F5F5>
验证码
</TD>
<TD bgColor=#F5F5F5>
<INPUT id=check type=text size=10 name=check>
<img src="test/random" id="checkimg" alt="随机图片"
title="验证图片" />
<a href="#" onClick="refresh()">看不清?</a>
</TD>
</TR>
<TR>
<TD bgColor=#F5F5F5 colspan=2 align=center>
<input type=submit value=登陆
onclick="return clientValidate()" class=btn3_mouseout
onmouseover="this.className='btn3_mouseover'"
onmouseout="this.className='btn3_mouseout'"
onmousedown="this.className='btn3_mousedown'">
<input type="button" value="注册"
onclick="javascript:window.location.href='regist2.jsp'"
class=btn3_mouseout
onmouseover="this.className='btn3_mouseover'"
onmouseout="this.className='btn3_mouseout'"
onmousedown="this.className='btn3_mousedown'">
<input type=button value=忘记密码
onclick="javascript:window.location.href='passforget.jsp'"
class=btn3_mouseout
onmouseover="this.className='btn3_mouseover'"
onmouseout="this.className='btn3_mouseout'"
onmousedown="this.className='btn3_mousedown'"> </TD>
</TR>
</TBODY>
</TABLE>
</form>
var oul=ttdd.children[0];
if(oul)
{
ttdd.removeNode(oul);
var oli=oul.children[0];
if(oli)
{
oul.removeChild(oli);
}
}
public class LoginAction extends ActionSupport
{
private String username;
private String password;
private String check;
private String login;
private LoginService loginService; public void setLoginService(LoginService loginService)
{
this.loginService = loginService;
} public String getUsername()
{
return username;
} public void setUsername(String username)
{
System.out.println("set username now ,and value is"+username);
this.username = username;
} public String getPassword()
{
return password;
} public void setPassword(String password)
{
System.out.println("set password now,and value is"+password);
this.password = password;
} public String getCheck()
{
return check;
} public void setCheck(String check)
{
System.out.println("set check now,and value is"+check);
this.check = check;
} public String getLogin()
{
return login;
} public void setLogin(String login)
{
this.login = login;
} public String execute() throws Exception
{
// this.getActionMessages().clear();
Map mapsession = ActionContext.getContext().getSession();
String randcheck = (String) mapsession.get("validateCode");
mapsession.put("validateCode", null);
if (!randcheck.equals(check))
{
// this.addFieldError("check.wrong", "验证码输入有误");
addActionMessage("验证码输入有误");
// this.addActionError("验证码输入有误");
return INPUT;
}
// addfielderror()和addActionError();
// 在execute里边 运行不行啊!!!!!!!!!!!!
// 改为addactionmessage方法就没问题了
System.out.println("=======in execute() now=======");
System.out.println("check is right in loginaction");
if (loginService.userpass(username, password))
{
System.out.println("userpass returns true");
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
session.setAttribute("username", username);
session.setAttribute("password", password);
session.setAttribute("login", "vip");
this.setLogin((String) session.getAttribute("login"));
System.out.println("the values login in session is"
+ (String) session.getAttribute("login"));
return SUCCESS;
} else
{
// this.addFieldError("username.wrong", "用户名或密码错误");
// this.addActionError("用户名或密码错误");
addActionMessage("用户名或密码错误");
return INPUT;
}
}