第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

用JavaWeb開發(fā)登錄功能使用學(xué)習(xí)ajax+jquery遇到點(diǎn)麻煩,在線等求解

用JavaWeb開發(fā)登錄功能使用學(xué)習(xí)ajax+jquery遇到點(diǎn)麻煩,在線等求解

慕粉3505864 2017-12-07 11:53:15
UserServlet代碼public?class?UserServlet?extends?BaseServlet?{ /** ?*?登錄的功能 ?*/ public?String?login(HttpServletRequest?req,?HttpServletResponse?resp)?{ //?7.驗(yàn)證碼驗(yàn)證 //?7.1獲取驗(yàn)證碼 String?code?=?req.getParameter("code"); //?7.2獲取生成的驗(yàn)證碼 String?rand?=?req.getSession().getAttribute("IdentifyCode").toString(); //?8.檢查驗(yàn)證碼 if?(code?!=?null?&&?!code.trim().equals(""))?{ if?(!code.equalsIgnoreCase(rand))?{ try?{ resp.getWriter().write("codeFalse"); }?catch?(IOException?e)?{ e.printStackTrace(); } }?else?{ //?1.接收數(shù)據(jù) Map<String,?String[]>?map?=?req.getParameterMap(); User?user?=?new?User(); System.out.println("獲取數(shù)據(jù):-------"?+?map); //?2.封裝數(shù)據(jù) try?{ BeanUtils.populate(user,?map); //?3.調(diào)用Service層處理數(shù)據(jù) UserService?us?=?new?UserService(); User?existUser?=?us.login(user); System.out.println("=======existUser========"?+?existUser); if?(existUser?==?null)?{ //?用戶登錄失敗 //?req.setAttribute("msg",?"用戶名或密碼錯(cuò)誤!"); resp.getWriter().write("LoginFail"); //?"/login/login2.jsp" }?else?{ req.getSession().setAttribute("existUser",?existUser); System.out.println("------用戶登錄成功!?。。?!-------"); resp.getWriter().write("LoginSuc"); } }?catch?(Exception?e)?{ e.printStackTrace(); } } return?null; } return?null; } }jsp頁面<%@?page?language="java"?import="java.util.*"?pageEncoding="UTF-8"%> <html> <head> <title>登陸操作</title> <meta?http-equiv="content-type"?content="text/html;?charset=utf8"?/> <link?rel="stylesheet"?type="text/css"?href="Styles/base.css"?/> <link?rel="stylesheet"?type="text/css"?href="Styles/admin-all.css"?/> <link?rel="stylesheet"?type="text/css"?href="Styles/bootstrap.min.css"?/> <link?rel="stylesheet"?type="text/css"?href="Styles/login.css"?/> <script?type="text/javascript"?src="Scripts/jquery.js"></script> <script?type="text/javascript"?src="Scripts/jquery.spritely-0.6.js"></script> <script?type="text/javascript"?src="Scripts/chur.min.js"></script> <script?type="text/javascript"> $(document).ready(function(){ $.ajaxSetup({cache:false});//清楚ajax //刷新驗(yàn)證碼 $("#randCode,#randCode2").click(function(e){ $("#randCode").attr("src","RandCodeServlet?t="+new?Date().getTime()); //阻止超鏈接默認(rèn)行為 e.preventDefault(); }); </script> </head> <body> <div?id="clouds"?class="stage"></div> <div?class="loginmain"></div> <div?class="row-fluid"> <form?name="form1"?method="post" action="${pageContext.request.contextPath?}/user"> <input?type="hidden"?name="method"?value="login"?/> <h1>聊?天?系?統(tǒng)</h1> <p> <label>帳&nbsp;&nbsp;&nbsp;號(hào):<input?type="text"?id="username" name="username"?/>?</label> </p> <p> <label>密&nbsp;&nbsp;&nbsp;碼:<input?type="password" id="password"?name="password"?/>?</label> </p> <p?class="pcode"> <label>&nbsp;&nbsp;&nbsp;驗(yàn)&nbsp;&nbsp;證&nbsp;&nbsp;碼:<input type="text"?id="txtCode"?name="code"?maxlength="4"?class="code"?/> <img?id="randCode"?src="RandCodeServlet"?title="看不清換一張" class="imgcode"?/>?<a?id="randCode2"?href="RandCodeServlet">換一張</a> </label> </p> <p?class="tip"?id="divMsg">&nbsp;</p> <hr?/> <input?id="submit"?type="submit"?value="?登?錄?" class="btn?btn-primary?btn-large?login"?/>?&nbsp;&nbsp;&nbsp;<input id="button2"?type="button"?value="?注?冊(cè)?"?class="btn?btn-large"?/> </form> </div> </body> </html> <script> </script>想用ajax+jquery對(duì)登錄檢驗(yàn),登陸成功,登陸失敗,賬號(hào)密碼驗(yàn)證碼不能為空的檢查,然后顯示在頁面上的<p class="tip" id="divMsg">&nbsp;</p>位置以下是自己寫的ajax+jquery的代碼,可是無法實(shí)現(xiàn),有人幫我修改一下嗎?? //登陸的業(yè)務(wù)操作 $("#submit").click(function(){ var?name=$("#username").val(); var?pass=$("#password").val(); var?code=$("#txtCode").val(); alert("name="+name+"pass"+pass+"code"+code); if(name!=""?&&?pass!=""?&&?code!=""){ //發(fā)出ajax請(qǐng)求 $.ajax({ type:"post", url:"${pageContext.request.contextPath?}/user?method=login", data:"action=Login&d="+(new?Date()).valueOf()+"&name="+name+"&pass="+pass+"&code"+code, success:function(responseText){ alert("--------"+data+"--------"); if(responseText=="LoginSuc"){ $("#divMsg").show().html("登陸成功!"); //登陸按鈕變色 $("#submit").attr("disabled","disabled"); window.location="chatRoom.jsp"; }else?if(responseText=="LoginFail"){ //登陸失敗 $("#divMsg").show().html("登陸失敗,請(qǐng)重新登陸!"); return?false; }else?if(responseText=="codeFalse"){ $("#divMsg").show().html("驗(yàn)證碼錯(cuò)誤!"); return?false; }else?if(responseText=="LoginNot"){ $("#divMsg").show().html("你已經(jīng)登陸過了"); return?false; } }, error:function(xmlHttpReq){ $("#divMsg").show().html("網(wǎng)絡(luò)故障:"+xmlHttpReq.status); } ? }); }else{ if(name=""){ $("#divMsg").show().html("賬號(hào)不能為空"); return?false; } if(pass=""){ $("#divMsg").show().html("密碼不能為空"); return?false; } if(code=""){ $("#divMsg").show().html("驗(yàn)證碼不能為空"); return?false; } } }); });等求解,謝謝謝謝?。。〉惹蠼?,謝謝謝謝!??!等求解,謝謝謝謝?。。?
查看完整描述

1 回答

?
堂堂堂堂糖糖糖童鞋

TA貢獻(xiàn)101條經(jīng)驗(yàn) 獲得超58個(gè)贊

既然是ajax提交表單,就不需要再form標(biāo)簽中指定action了,簡(jiǎn)單改了一下js代碼:

$(function?()?{
????$('#submit').on('click',?function?()?{
????????var?name=$("#username").val();
????????var?pass=$("#password").val();
????????var?code=$("#txtCode").val();
????????
????????function?validateForm?()?{
????????????if?(!name)?{
????????????????$('#divMsg').text('賬號(hào)不能為空').show();
????????????????return?false
????????????}
????????????else?if?(!pass)?{
????????????????$('#divMsg').text('密碼不能為空').show();
????????????????return?false
????????????}
????????????else?if?(!code)?{
????????????????$('#divMsg').text('驗(yàn)證碼不能為空').show();
????????????????return?false
????????????}
????????????return?true
????????}
????????
????????if?(validateForm())?{?//?校驗(yàn)通過
????????????$('#divMsg').text('').hide();?//?清空信息
????????????//?發(fā)送ajax請(qǐng)求
????????????alert('發(fā)送ajax');
????????}
????})
})


查看完整回答
反對(duì) 回復(fù) 2017-12-07
  • 慕粉3505864
    慕粉3505864
    謝謝你的回答,我想問多一個(gè)我的表單是這樣子的: <form name="form1" method="post" action="${pageContext.request.contextPath }/user"> <input type="hidden" name="method" value="login" /> </form> 提交表單 訪問我UserServlet.java里面的login()方法,進(jìn)行登錄,我后臺(tái)已經(jīng)寫好了當(dāng)?shù)顷懯r(shí)候的提示信息:假設(shè)登陸失敗,執(zhí)行 resp.getWriter().write("LoginFail"); 然后我們前端頁面接收進(jìn)行顯示(responseText)錯(cuò)誤信息。 你說表單就不需要再form標(biāo)簽中指定action了 那么我錯(cuò)誤的地方應(yīng)該就在以下這串代碼中 $.ajax({ type:"post", url:"${pageContext.request.contextPath }/user?method=login", data:"action=Login&d="+(new Date()).valueOf()+"&name="+name+"&pass="+pass+"&code"+code, 我感覺我的url跟data里面寫錯(cuò)了,應(yīng)該如何正確寫呢?
  • 慕粉3505864
    慕粉3505864
    謝謝你的回答,我想問多一個(gè)我的表單是這樣子的: <form name="form1" method="post" action="${pageContext.request.contextPath }/user"> <input type="hidden" name="method" value="login" /> </form> 提交表單 訪問我UserServlet.java里面的login()方法,進(jìn)行登錄,我后臺(tái)已經(jīng)寫好了當(dāng)?shù)顷懯r(shí)候的提示信息:假設(shè)登陸失敗,執(zhí)行 resp.getWriter().write("LoginFail"); 然后我們前端頁面接收進(jìn)行顯示(responseText)錯(cuò)誤信息。 你說表單就不需要再form標(biāo)簽中指定action了 那么我錯(cuò)誤的地方應(yīng)該就在以下這串代碼中 $.ajax({ type:"post", url:"${pageContext.request.contextPath }/user? method=login", data:"action=Login&d="+(new Date()).valueOf()+"&name="+name+"&pass="+pass+"&code"+code, ?我感覺我的url跟data里面寫錯(cuò)了,應(yīng)該如何正確寫呢?
  • 慕粉3505864
    慕粉3505864
    有些亂,你看上面我添加答案,里面的提問,謝謝
  • 1 回答
  • 0 關(guān)注
  • 2748 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)