AJAX验证数据库内容并显示在页面
2024-09-21 18:22:59
功能实现:
在jsp页面中填写文本框内容,光标离开文本框,在本页面的相应地方获取数据库中改值所对应的其他数据。
servlet:
request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
// 调用servlet层去数据库查找是否有相同用户名 并返回到页面中的其他记录
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();
jquery:
$(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));
}
}
});
});
});
最新文章
- Java 中使用javah编译头文件出现找不到类的情况
- winform 可拖动的自定义Label控件
- SLAM拾萃(3):siftGPU
- vc设置按钮文字颜色
- [Ruby] Ruby Variable Scope
- group by 汇总
- Dubbo源码学习--服务发布(ServiceBean、ServiceConfig)
- 第二十六天 蛰伏的Hibernate遇到春日的暖阳 —Spring MVC 集成Hibernate使用(一)
- 有奖试读—Windows PowerShell实战指南(第2版)
- 利用pytesser识别图形验证码
- Spring Bean 生命周期测试
- QGridLayout
- 安卓程序中手机后退键与标题栏后退键是不同的,前者回出发onBackPressed()函数,后者需要重重写temclick函数
- Linux环境下Node.js的安装配置
- Notepad++ 列操作
- json等序列化模块 异常处理
- 半夜思考, 为什么建议重写 equals() 方法时, 也要重写 hashCode() 方法
- nvidia显卡驱动
- 1: 介绍Prism5.0(纯汉语版)
- jmeter聚合报告详解
热门文章
- (转) Pointers
- MVC再次学习1
- 微信开发之门店管理{";errcode";:40097,";errmsg";:";invalid args hint: [xxxxxxx]";}
- Firebug介绍及使用技巧
- pubwin会员合并
- 阿里巴巴JAVA常考面试题及汇总答案
- 学习http的一个网站
- CentOS6下编译安装Python2.7.6方法
- Bitmap 与ImageSource之间的转换
- Quartz.NET作业调度框架详解