原生态:
servlet:
public class Servlet extends javax.servlet.http.HttpServlet {
protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
String uname = request.getParameter("uname");
if(uname.equals("admin")){
response.getWriter().write("true");
}else{
response.getWriter().write("false");
}
}
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
doPost(request,response);
}
}
jsp页面(原生态):
第二种:
红框是修改地方。
第三种(最简单得):
$(function(){
$("[name=uname]").blur(function(){
$.ajax({
url:"/Servlet",
type:"POST",
data:"uname="+$("[name=uname]").val(),
success:function(data){
$("#msg").html(data)
}
})
});
});
执行结果: