如何用ajax实现用户登录
yfsea 2009-03-04 12:17:27 jsp中的代码如下:
var name=document.forms[0].username.value;
var xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.open("GET","http://localhost:8080/TestDWR/login.do",true);
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
}
}
xmlHttp.send();
}
当请求到达StrutsAction的execute()方法后,
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
LoginForm loginForm = (LoginForm) form;
String name = loginForm.getUsername();
String pwd = loginForm.getPwd();
UserDAO dao = new UserDAO();
return mapping.findForward("suc");
//我希望能跳转到"suc"对应的jsp页面中,不知道有什么办法.
}
其实我的想法就是用ajax实现用户登录,当在jsp中单击“登录”时,对数据进行验证后,异步跳转到成功页面,
在此请教高手!