日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

登錄時(shí)“記住用戶名”

系統(tǒng) 1969 0
登錄時(shí)需要用戶“記住用戶名”,如圖:
登錄時(shí)“記住用戶名”

紅色部分需要注意的,
if("index".equals(action)){//顯示首頁登錄
? CookieUtil util=new CookieUtil(request,response,365*24*3600);
? Cookie cookie=util.getCookie("userId");
? if(cookie!=null){//需要判斷是否記錄了用戶名
?? request.getSession().setAttribute("userId", util.getCookieValue("userId"));
?? request.getSession().setAttribute("remember", "1");
? }
return mapping.findForward("index");
}

else
if ("login".equals(action)) {//點(diǎn)擊登錄時(shí)
System.out.println("----------------login--------------");
String userId = request.getParameter("userId");
String password = request.getParameter("password");

CookieUtil util=new CookieUtil(request,response,-1);
String authCode=util.getCookieValue("AUTHCODE");
System.out.println("authCode="+authCode);
if (!authCode.equals(form.getAuthCode())) {//驗(yàn)證碼不正確
msg="驗(yàn)證碼不正確!";
request.setAttribute("msg", msg);
return mapping.getInputForward();
}
User user = (User)this.getBaseService().get("from User where userId = '"+userId+"'");
if(user==null){
msg="用戶名不存在!";
request.setAttribute("msg", msg);
return mapping.getInputForward();
}
if(!user.getPassword().equals(StringUtil.hash(password))){
msg="密碼不正確!";
request.setAttribute("msg", msg);
return mapping.getInputForward();
}

//是否保存用戶名到cookie
String remember = request.getParameter("remember");

if(remember==null){//不勾選,則刪除之
? CookieUtil util2=new CookieUtil(request,response,0);
? util2.deleteCookie("userId");
}else{//勾選,則保存之
? CookieUtil util2=new CookieUtil(request,response,365*24*3600);
? util2.addCookie("userId", userId);//保存用戶名到cookies
}


........
)
需要CookieUtil類,見: http://gundumw100.iteye.com/admin/blogs/494328
//jsp文件如下:
<table width="100%" style="margin-top:30px">
? <tbody>
? <tr>
??? <td align="right">用戶名:</td>
??? <td align="left"> <input type="text" id="userId" name="userId" value="${sessionScope.userId }" /> </td>
? </tr>
? <tr>
??? <td align="right">密碼:</td>
??? <td align="left"><input type="password" id="password" name="password" value="" /></td>
? </tr>
? <tr>
??? <td align="right">驗(yàn)證碼:</td>
??? <td align="left"><input type="text" style="width:90px" id="authCode" name="authCode"/><a href="#" onclick="javascript:refresh();"><img height="18" src="authimg" id="checkCodeImg" border="0"></a></td>
</tr>
???? <tr>
???? <td align="right"></td>
???? <td align="left">
???? <input type="checkbox" id="remember" name="remember" value="1" ${sessionScope.remember==1?'checked':'' }>記住用戶名

???? </td>
???? </tr>
<tr>
? <td colspan="2"><div align="center" style="color:red">${requestScope.msg }</div></td>
</tr>
<tr>
??? <td colspan="2" align="center">
??? <input id="imgButton" name="imgButton" type="image" src="images/login.gif" />
<a href="login.portal?action=register">注冊</a>
</td>
</tr>
</tbody>
</table>




登錄時(shí)“記住用戶名”


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會(huì)非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 府谷县| 嘉善县| 临颍县| 长泰县| 富阳市| 厦门市| 东平县| 江北区| 谷城县| 高阳县| 本溪| 阜城县| 衢州市| 高清| 榆林市| 无为县| 子洲县| 太白县| 阿鲁科尔沁旗| 黄平县| 四平市| 西青区| 睢宁县| 玉田县| 文安县| 广宗县| 横山县| 府谷县| 长葛市| 宜州市| 百色市| 孙吴县| 凤山县| 城步| 马山县| 木兰县| 苍溪县| 贵阳市| 柯坪县| 沂南县| 澄城县|