String.prototype.Trim = function() {
      return this.replace(/(^\s*)|(\s*$)/g,""); 
      }
function CheckNull(){
if($("#username").val()==""){
      $("#usernull").text("账号不能为空");
      return false;
}else{
  $("#usernull").text("");
return true;
}
if($("#password").val()==""){
$("#pwdnull").text("密码不能为空");
return false;
}else{
return true;
}
}
$(function(){
$("#submit").click(function (event){
if(CheckNull()==true){
$.ajax({
 url:"Login",
 type:"POST",
 dataType:"text",
 data:{userName:$("#username").val(),password:$("#password")},
 success:function(data){
 alert("ss");
   if(data.Trim()=="false"){
    alert("账号密码不匹配");
   }
 }
});
}else{
return false;
}
});
});
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html");
response.setCharacterEncoding("GBK");
PrintWriter out = response.getWriter();
user userInfo = new user();
UserBll ubll = new UserBll();
userInfo.setUserName(request.getParameter("userName"));
userInfo.setPassword(request.getParameter("password"));
//HttpSession session = request.getSession(true);
System.out.println(ubll.CheckLogin(userInfo));
if(ubll.CheckLogin(userInfo)==true){
//session.setAttribute("user", userInfo);
response.sendRedirect("main.jsp");
}
else{
out.println("false");
}
out.flush();
out.close();
}
 public boolean CheckLogin(user userInfo)
  {
  try
  {
  return udal.CheckLogin(userInfo)==true?true:false;
  }catch(Exception e)
  {
  e.printStackTrace();
  return false;
  }
  }
boolean result=false;
       ResultSet res = null;
       String sql = "select * from [user] where userName='"+userInfo.getUserName()+"' and password='"+userInfo.getPassword()+"'";
       try
       {
       res= BaseBao.GetResuelSet(sql);
       if(res.next())
       result=true;
       else
       result=false;       }catch(Exception e)
       {
       e.printStackTrace();
       }finally
       {        }
       return result;就是一个简单的登陆功能但是 我点击登陆的时候没反应而且 eclipse 还没响应了 只要单击登陆 eclipse就没响应 结果也不出现

解决方案 »

  1.   

    确认你的数据有提交到servlet?
    貌似没有什么会影响System.out.println(ubll.CheckLogin(userInfo));的执行,所以我判断你的请求并没有提交到servlet,确认你的提交form的action属性和servlet的url
      

  2.   

    加断点调试,firebug看出的什么错
      

  3.   

    $.ajax  提示jquery 堆栈溢出  什么意思
    以前 也是怎么提交 也没出现这个问题额
      

  4.   

    大概看了下 要去吃饭了 首先你的js验证从功能上有问题 else里的return true多余了 每次要判断完账号之后即return true了 无法验证password是否空 功能问题 但你出的问题应该不是这个影响的 吃饭回来给你看看1
      

  5.   

    response.sendRedirect("main.jsp");
      这句话为什么不跳转呢 断点调试的时候 上面的代码都依次走过了可是就不跳转啊