在jsp頁面中填寫文本框內(nèi)容,光標(biāo)離開文本框,在本頁面的相應(yīng)地方獲取數(shù)據(jù)庫中改值所對應(yīng)的其他數(shù)據(jù)。
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
// 調(diào)用servlet層去數(shù)據(jù)庫查找是否有相同用戶名 并返回到頁面中的其他記錄
String client_id = request.getParameter("client_id");
ClientServices clientServices = new ClientServices();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Client client = clientServices.findClientById(client_id);
if (client != null) {
out.print(URLEncoder.encode(client.getClient_name(), "utf-8"));
} else {
out.print("false");
}
out.flush();
out.close();
$(document).ready(function() {
$("#client_id").blur(function() {
$.ajax({
type : 'POST',
url : 'servlet/validServlet?client_id=' + $(this).val(),
data : 'client_id=' + $("#client_id").val(),
success : function(msg) {
if (msg == 'false') {
alert("沒有此人");
} else {
//utf-8解碼解決中文亂碼
$("#clientInfo").html(decodeURI(msg));
$("#clientInfo").attr("value", decodeURI(msg));
}
}
});
});
});