ajax
已经能够成功验证了
function checkUser(){
var username = $("#username").val();
var password = $("#password").val();
$.ajax({
type: "post",
url: "logincheck",
data: {"username":username,"password":password},
success:function(data){
location.href = "index.jsp";
}
});
}
servlet
String un = request.getParameter("username");
String pd = request.getParameter("password");
userCheck uc = new userCheck();
String res = uc.getUser(un,pd);
if(!res.equals("userwrong") && !res.equals("passwordwrong"))
{
**request.getSession().setAttribute("username", res);**验证后的数据已经保存在session里了
}
html
<%String username=(String)request.getSession().getAttribute("username");
if(username == null){
%>
<input type="button" class="buttontype2" id="login" value="登录" onclick="checkUser();"
问题就是我需要重新刷新一下这个页面,才能进入if判断语句去读取session,我就是不知道如何刷新这个页面,在服务器重定位还是在ajax seccess回调函数进行刷新页面?求大神解答!