注冊驗證是可以正常進入服務(wù)器并于controller中的checkRegister交互的,并且控制臺能輸出sql語句。但是登錄卻不行,檢查很多遍沒發(fā)現(xiàn)寫錯什么,但是并沒有進入到checkLogin方法,連方法內(nèi)部的systemout一個都沒輸出來。最讓我不解的是,用谷歌和ie瀏覽器時,不進對應(yīng)的方法不說,內(nèi)存占用逐漸上升飆紅了,網(wǎng)頁關(guān)掉就恢復(fù)正常。而這些問題,注冊頁面統(tǒng)統(tǒng)沒有。。我查來查去真不知道是什么原因了,請各位大神幫忙指點分析一下。下面貼上源碼登錄的JS:<script?type="text/javascript"?src="<%=path?%>/statics/js/jquery.js"></script>
????<script?type="text/javascript">
???? $(document).ready(function(){
???? $("input").blur(function(){
???? var?ele=$(this);
???? var?getValue=ele.val();//獲取創(chuàng)建用戶時輸入的文本信息
???? if($(this).is("#cardId")){
???? var?reg=/^\d{18,18}$/;
???? if(reg.test(getValue)==false){
???? flag=false;
???? ele.attr("style","color:red;border:1px?solid?red;");
???? ele.next().attr("style","color:red;").html(" 賬號輸入有誤!");
???? }else{
ele.attr("style","color:green;border:1px?solid?green");
ele.next().attr("style","color:green;").html(" 賬號輸入正確!");
? }
???? }else?if($(this).is("#password")){
???? var?reg=/^\w{6,}$/;
???? if(reg.test(getValue)==false){
???? ele.attr("style","color:red;border:1px?solid?red;");
???? ele.next().attr("style","color:red;").html(" 密碼輸入有誤!");
???? }else{
???? ele.attr("style","color:green;border:1px?solid?green");
ele.next().attr("style","color:green;").html(" 密碼輸入正確!"); }
???? }
????
???? });
???? $("form").submit(function(){
???? alert(1);
???? var?result=false;
???? var?cardId=$("#cardId");
???? var?password=$("#password");
???? $.ajax({
???? async:false,
???? url:"<%=path%>/users/checkLogin",
???? type:"post",
???? data:{"cardId":cardId,"password":password},
???? dataType:"json",
???? success:function(data,xstatus,xhr){
???? if(data==1){
???? alert("該賬號不存在,請先注冊!")
???? }else?if(data==2){
???? alert("登錄失敗,賬號密碼不匹配!")
???? }else?if(data==3){
???? alert("登錄失敗,該賬號已凍結(jié)!")
???? }else?if(data==0){
???? result=true;
???? }
???? },
???? error:function(){
???? alert(4);
???? }
???? });
???? return?result;
???? });
???? });
???</script>登錄的JSP中HTML表單:?<body>
?? <sp:form?modelAttribute="users"?action="/users/login"?method="POST">
?? <div?align="center">
?? <h2>房產(chǎn)信息查詢系統(tǒng)</h2>?
?? <table>
?? <tr><td>請輸入身份證號</td><td><sp:input?path="cardId"?/><span/></td></tr>
?? <tr><td>請輸入密碼</td><td><sp:input?path="password"?/><span/></td></tr>
?? </table>
?? <tr><td><input?type="submit"?value="登錄"?/></td><td><a?href="<%=basePath%>users/register">注冊</a></td></tr>
?? </div>?
?? </sp:form>
??</body>登錄與注冊的后端處理:@Controller
@RequestMapping(value="/users")
public?class?UserController{
@Resource
private?IUsersService?usersService;
private?Map<Integer,Users>?usersList;
//用戶登錄
@RequestMapping(value="/login",method=RequestMethod.GET)
public?String?login(Model?model){
Users?users=new?Users();
model.addAttribute(users);
return?"_login";
}
@RequestMapping(value="/login",method=RequestMethod.POST)
public?String?login(Users?users,Model?model){
model.addAttribute("users",users);
return?"viewIndex";
}
@RequestMapping(value="/checkLogin",method=RequestMethod.POST)
public?void?checkLogin(HttpServletRequest?request,
HttpServletResponse?response,Users?user,Model?model){
try?{
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String?cardId?=?request.getParameter("cardId");
System.out.println(cardId);
String?pw=request.getParameter("password");
System.out.println(pw);
Users?u=usersService.getUserByCardId(cardId);
String?message=null;
if(u==null||!cardId.equals(u.getCardId())){
message="[1]";//該賬號不存在,請先注冊!
System.out.println("該賬號不存在,請先注冊");
}else?if(!cardId.equals(u.getCardId())||!pw.equals(u.getPassword())){
message="[2]";//登錄失敗,身份證號或密碼錯誤!
System.out.println("登錄失敗,身份證號或密碼錯誤!");
}else?if(u.getStatus()==0){
message="[3]";//登錄失敗,該賬號已被凍結(jié)!
System.out.println("登錄失敗,該賬號已被凍結(jié)!");
}else{
message="[0]";
System.out.println("登錄成功。。。");
}
PrintWriter?out=?response.getWriter();
out.write(JSONArray.fromObject(message).toString());
out.close();
}?catch?(IOException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
}
//用戶注冊
@RequestMapping(value="/register",method=RequestMethod.GET)
public?String?register(Model?model){
Users?users=new?Users();
model.addAttribute(users);
return?"_register";
}
@RequestMapping(value="/register",method=RequestMethod.POST)
public?String?register(Users?users,Model?model){
Integer?gender=new?Integer(users.getCardId().substring(17));
if(gender%2==0)gender=0;else?gender=1;
users.setGender(gender);
Date?createTime=new?Date(System.currentTimeMillis());
users.setCreateTime(createTime);
users.setStatus(1);
usersService.insertUsers(users);
return?"_login";
}
//注冊驗證
@RequestMapping(value="/checkRegister",method=RequestMethod.POST)
public?void?checkRegister(HttpServletRequest?request,
HttpServletResponse?response,Users?user,Model?model){
try?{
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String?message=null;
String?id?=?request.getParameter("cardId");
Users?u=usersService.getUserByCardId(id);
if(u==null){
message="[0]";//代表可以注冊
}else{
message="[1]";//代表已存在
}
PrintWriter?out=?response.getWriter();
out.write(JSONArray.fromObject(message).toString());
out.close();
}?catch?(IOException?e)?{
e.printStackTrace();
}
}
}注冊的JS:<script?type="text/javascript"?src="<%=path?%>/statics/js/jquery.js"></script>
????<script?type="text/javascript">
???? $(document).ready(function(){
???? $("input").blur(function(){
???? var?ele=$(this);
???? var?flag=true;
???? var?getValue=ele.val();//獲取創(chuàng)建用戶時輸入的文本信息
???? if($(this).is("#cardId")){
???? var?reg=/^\d{18,18}$/;
???? if(reg.test(getValue)==false){
???? flag=false;
???? ele.attr("style","color:red;border:1px?solid?red;");
???? ele.next().attr("style","color:red;").html(" 請輸入正確的身份證號碼");
???? }else{
???? $.ajax({
???? async:false,
???? url:"<%=path%>/users/checkRegister",
???? type:"post",
???? data:{"cardId":getValue},
???? dataType:"json",
???? success:function(data,xstatus,xhr){
???? if(data==1){
???? flag=false;
???? ele.attr("style","color:red;border:1px?solid?red");
???? ele.next().attr("style","color:red").html(" 此身份證已注冊!");
???? return;//此處return和break效果相同
???? }else{
???? flag=true;
ele.attr("style","color:green;border:1px?solid?green");
ele.next().attr("style","color:green;").html(" 此身份證可以注冊!");
???? }
???? },
???? error:function(){
???? alert(4);
???? }
???? });
???? }
???? }else?if($(this).is("#name")){
???? var?reg=/^\w{6,25}$/;
???? if(reg.test(getValue)==false){
???? flag=false;
???? ele.attr("style","color:red;border:1px?solid?red;");
???? ele.next().attr("style","color:red;").html(" 用戶名格式錯誤");
???? }else{
???? flag=true;
???? ele.attr("style","color:green;border:1px?solid?green");
ele.next().attr("style","color:green;").html(" 用戶名格式正確"); }
???? }
???? else?if($(this).is("#password")){
???? var?reg=/^\w{6,}$/;
???? if(reg.test(getValue)==false){
???? flag=false;
???? ele.attr("style","color:red;border:1px?solid?red;");
???? ele.next().attr("style","color:red;").html(" 密碼格式錯誤");
???? }else{
???? flag=true;
???? ele.attr("style","color:green;border:1px?solid?green");
ele.next().attr("style","color:green;").html(" 密碼格式正確"); }
???? }
???? else?if($(this).is("#confirmpassword")){
???? var?reg=/^\w{6,}$/;
???? if(reg.test(getValue)==true&&getValue==$("#password").val()){
???? flag=true;
???? ele.attr("style","color:green;border:1px?solid?green;");
???? ele.next().attr("style","color:green;").html(" 密碼格式正確");
????
???? }else{
???? flag=false;
???? ele.attr("style","color:red;border:1px?solid?red");
ele.next().attr("style","color:red;").html(" 密碼格式錯誤"); }
???? }
???? });
???? $("form").submit(function(){
???? if(flag=true){
???? event.returnValue=confirm("注冊已成功,現(xiàn)在去登錄嗎!")
???? }
???? });
???? });
????
????</script>注冊的JSP中HTML表單:<body>
?? <sp:form?modelAttribute="users"?action="/users/register"?method="POST">
?? <div?align="center">
?? <h2>賬號注冊</h2>?
?? <table>
?? <tr><td>身份證號</td><td><sp:input?path="cardId"?/><span/></td></tr>
?? <tr><td>用戶名</td><td><sp:input?path="name"?/><span/></td></tr>
?? <tr><td>密碼</td><td><sp:input?path="password"?/><span/></td></tr>
?? <tr><td>確認(rèn)密碼</td><td><sp:input?path="confirmpassword"?/><span/></td></tr>
?? </table>
?? <tr><td><input?type="submit"?value="注冊"?/></td><td><input
type="button"?value="返回"?onclick="history.go(-1)"?/></td></tr>
?? </div>?
?? </sp:form>
??</body>
- 3 回答
- 0 關(guān)注
- 12610 瀏覽
添加回答
舉報
0/150
提交
取消