前臺:
ajax:
$(document).ready(function(){
$("#email").blur(function(){
$("#email").css("background-color","#D6D6FF");
$.ajax({type:"post",url:"check_email.do",data:{‘email‘:$("#email").val()},
success:function(data){
if(data==2){
$("#content").html("
郵箱已經存在
");$(".btn").attr("disabled", true);
}
if(data==1)
{
$("#content").html("
$(".btn").attr("disabled", false);
}
if(data==13)
{
$("#content").html("
郵箱不能為空
");$(".btn").attr("disabled", true);
}
}
});
});
});
后臺數據處理:
@RequestMapping("check_email.do")
public void checkEmail(HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter out= response.getWriter();
String email= request.getParameter("email");
// 檢查數據庫是否重名
boolean exist = service.emailExist(email);
if (!exist) {
Servlets.writeHtml(response, "1");
} else {
Servlets.writeHtml(response, "2");
}
if(StringUtils.isBlank(email))
Servlets.writeHtml(response, "3");
out.close();
/*if (StringUtils.isBlank(email)) {
Servlets.writeHtml(response, "false");
return;
}
if (StringUtils.equals(email, original)) {
Servlets.writeHtml(response, "true");
return;
}
// 檢查數據庫是否重名
boolean exist = service.emailExist(email);
if (!exist) {
Servlets.writeHtml(response, "true");
} else {
Servlets.writeHtml(response, "false");
}*/
}
元生后臺:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html:charset=utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out= response.getWriter();
request.setCharacterEncoding("utf-8");
String username= request.getParameter("username");
String password= request.getParameter("password");
if(username.equals("洪帆"))
{
/*out.println("
"+username+"
");*/out.println("1");
/*out.println("
"+password+"
");out.println("
"+"用戶名準確"+"
");*/}else{
out.print(username);
out.print("用戶名或密碼錯誤");
}
out.close();
}
jquery校驗textarea必填
$("#sub1).click(function(){
var text1=$("#text1").val();
if(text1==""){
alert("不能為空!");
$("#text1").select();
$("#text1").focus();
}else{
$("#form1").submit();
}
})