IDEA后台执行日志
DEBUG [http-nio-8080-exec-8] - PooledDataSource forcefully closed/removed all connections.
DEBUG [http-nio-8080-exec-8] - Opening JDBC Connection
DEBUG [http-nio-8080-exec-8] - Created connection 1075980333.
DEBUG [http-nio-8080-exec-8] - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@4022282d]
DEBUG [http-nio-8080-exec-8] - ==> Preparing: select * from users where userName = ? and userPassword = ?
DEBUG [http-nio-8080-exec-8] - ==> Parameters: addd(String), G@@(String)
DEBUG [http-nio-8080-exec-8] - <== Total: 0
绯荤粺寮傚父
close database
DEBUG [http-nio-8080-exec-8] - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@4022282d]
DEBUG [http-nio-8080-exec-8] - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@4022282d]
DEBUG [http-nio-8080-exec-8] - Returned connection 1075980333 to pool.
database is closed
select resultnull
DEBUG [http-nio-8080-exec-8] - Using 'application/json', given [application/json, text/javascript, /;q=0.01] and supported [application/json, application/*+json]
DEBUG [http-nio-8080-exec-8] - Nothing to write: null body
DEBUG [http-nio-8080-exec-8] - Completed 200 OK
浏览器控制台日志
{readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}
abort: ƒ (e)
always: ƒ ()
complete: ƒ ()
done: ƒ ()
error: ƒ ()
fail: ƒ ()
getAllResponseHeaders: ƒ ()
getResponseHeader: ƒ (e)
overrideMimeType: ƒ (e)
pipe: ƒ ()
progress: ƒ ()
promise: ƒ (e)
readyState: 4
responseText: ""
setRequestHeader: ƒ (e,t)
state: ƒ ()
status: 200
statusCode: ƒ (e)
statusText: "parsererror"
success: ƒ ()
then: ƒ ()
[[Prototype]]: Object
Ajax请求代码
function admin_login(){
var username = $.trim($("#username").val());
var password = $.trim($("#userpassword").val());
if(username === ""){
alert("请输入用户名");
return false;
}else if(password === ""){
alert("请输入密码");
return false;
}
//开始传递到后端校验
var data= {userName:username,userPassword:password};//userName、userPassword必须与后端的接收变量名一致
$.ajax({
type:"POST",
url:'dologin',
data:data,
dataType:'json',
/*success: onSuccess, //请求成功回调方法
error: onError //请求失败回调方法*/
success:function(data){
//alert(msg);
if(data===null){
window.alert("用户名或密码错误!")
}
else{
window.alert("登录成功"+data.userName)
console.log(data)
/* window.location.href = "success"*/
}
},
error:function (data){
window.alert("服务器连接失败"+data.userName)
console.log(data)
}
});
}
你是form表单提交发送异步请求?
error 是请求失败的时候才会访问的;不是返回为空时访问的。
返回为空,按你的代码逻辑会执行success对应的24行代码。
如果返回为空,进入了error。说明发生了空指针异常。如果你不希望进入error;就要处理这种情况,不抛出异常。
另外,建议把21行,32行的参数data,换个名称。它和12的data容易混淆,
因为你查询为空啊,null转不了json,
我猜测你的代码是这样的
UserInfo user = xxxxxx.xxxxx(xxxx,xxx);
return user;//
就没有考虑user为空的情况
UserInfo user = xxxxxx.xxxxx(xxxx,xxx);
//改成这样,你不会有null的问题
if(user ! =null){
retturn user;
}
return xxxxxxx;