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就没响应 结果也不出现
貌似没有什么会影响System.out.println(ubll.CheckLogin(userInfo));的执行,所以我判断你的请求并没有提交到servlet,确认你的提交form的action属性和servlet的url
以前 也是怎么提交 也没出现这个问题额
这句话为什么不跳转呢 断点调试的时候 上面的代码都依次走过了可是就不跳转啊