怎么用jquery和ssh实现验证用户登录!
我的js代码:
<script>
function checkStudent(){
$.ajax({
cache: true,
type: "POST",
url:"loginAction!checkStudent",
data:$('#loginStudent').serialize(),// 你的formid
async: false,
success: function(data) {
document.getElementById("loginStudent").submit();
var i = parstInt(data);
if(i == 1){
alert("success");
window.location.href="student.jsp";
}
else if (i==0){
alert("账号或密码错误");
}
}
});
}
</script>
表单那里的代码:
<div align="center">
<form id="loginStudent">
姓名:<input type="text" name="sname" />
密码:<input type="text" name="password" />
<input type="button" value="提交" id="btn" onclick="checkStudent()" />
</form>
还有action中的代码:/* check student part */
public String checkStudent() throws IOException{
out = ServletActionContext.getResponse().getWriter();
List<Student> students = loginService.checkLoginStudent(model.getSname(), model.getPassword());
if(students.size()>0){
Student stu = students.get(0);
id = stu.getStudentId();
System.out.println(id);
out.write("1");
out.flush();
out.close();
return "student";
}
else {
out.write("0");
out.flush();
out.close();
return "loginStudent";
}
}
试了一个下午!就是不行!无语了,求各位帮忙!