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

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么輸入用戶名后登陸成功查看用戶信息用戶名變成了和密碼一樣的字符?

這個是查看用戶信息

<h1>查看用戶信息</h1>

? <hr>

? <%

? request.setCharacterEncoding("utf-8");

? String username = "";

? String password = "";

? ? Cookie[] cookies = request.getCookies();

? ? ?if(cookies!=null && cookies.length>0)

? ? ?{

? ? ?for(Cookie c : cookies)

? ? ?{

? ? ? ? if(c.getName().equals("username") || c.getName().equals("password"))

? ? ? ? {

? ? ? ? ? ? username = URLDecoder.decode(c.getValue(),"utf-8");

? ? ? ? ? ? password = URLDecoder.decode(c.getValue(),"utf-8");

? ? ? ? }

? ? ?}

? ? ?}

? ?%>

? <br>

? <br>

? <br>

? 用戶名:<%=username %><br>

? 密碼:<%=password %><br>



這個是登錄成功驗證頁面

<h1>登陸成功</h1>

? <hr>

? <br>

? <br>

? <br>

? <%

??

? request.setCharacterEncoding("utf-8");

? //首先判斷用戶是否選擇了記住登錄狀態(tài)

? String[] isUseCookie =request.getParameterValues("isUseCookie");

? if(isUseCookie!=null && isUseCookie.length>0)

? {

? ? ?//把用戶名和密碼保存在Cookie對象里面

? ? ?String username = URLEncoder.encode(request.getParameter("username"),"utf-8");

? ? ?//使用URLEncoder解決無法在Cookie當(dāng)中保存字符串問題

? ? ?String password = URLEncoder.encode(request.getParameter("password"),"utf-8");

? ? ?

? ? ?

? ? ?

? ? ?

? ? ?Cookie usernameCookie = new Cookie("username",username);

? ? ?Cookie passwordCookie = new Cookie("password",password);

? ? ?usernameCookie.setMaxAge(864000);//設(shè)置最大生存期限為十天

? ? ?passwordCookie.setMaxAge(864000);

? ? ?response.addCookie(usernameCookie);

? ? ?response.addCookie(passwordCookie);

? }

? else

? {

? ? ?Cookie[] cookies = request.getCookies();

? ? ?if(cookies!=null && cookies.length>0)

? ? ?{

? ? ?for(Cookie c : cookies)

? ? ?{

? ? ? ? if(c.getName().equals("username") || c.getName().equals("password"))

? ? ? ? {

? ? ? ? ? ? c.setMaxAge(0);//設(shè)置Cookie失效

? ? ? ? ? ? response.addCookie(c);

? ? ? ? ? ??

? ? ? ? }

? ? ?}

? ? ?}

? }

? ?%>

? <a href="users.jsp" target="_blank">查看用戶信息</a>


這個是用戶登錄頁面

?<h1>用戶登錄</h1>

? <hr>

? ?<%

? ?request.setCharacterEncoding("utf-8");

? String username = "";

? String password = "";

? ? Cookie[] cookies = request.getCookies();

? ? ?if(cookies!=null && cookies.length>0)

? ? ?{

? ? ?for(Cookie c : cookies)

? ? ?{

? ? ? ? if(c.getName().equals("username") || c.getName().equals("password"))

? ? ? ? {

? ? ? ? ? ? username = URLDecoder.decode(c.getValue(),"utf-8");

? ? ? ? ? ? password = URLDecoder.decode(c.getValue(),"utf-8");

? ? ? ? }

? ? ?}

? ? ?}

? ?%>

? <form name="loginForm" action="dologin.jsp" method="post">

? <table>

? <tr>

? <td>用戶名:</td>

? <td><input type="text" name="username" value="<%= username%>"/></td>

? </tr>

? <tr>

? <td>密碼:</td>

? <td><input type="password" name="password" value="<%= password%>"/></td>

? </tr>

? <tr>

? <td colspan="2"><input type="checkbox" name="isUseCookie" checked="checked" >十天內(nèi)記住我的登錄狀態(tài)</td>

? </tr>

? <tr>

? <td colspan="2" align="center"><input type="submit" value="登錄"/><input type="reset" value="取消"/></td>

? </tr>

? </table>


正在回答

1 回答

? ? ? ? if(c.getName().equals("username") || c.getName().equals("password"))

? ? ? ? {

??????????? username = URLDecoder.decode(c.getValue(),"utf-8");

? ? ? ? ? ? password = URLDecoder.decode(c.getValue(),"utf-8");

? ? ? ? }

這個不能寫在一起 如下:

??? ???if(c.getName().equals("username")) {
??? ????username = URLDecoder.decode(c.getValue(),"utf-8");
??? ???}
??? ???if(c.getName().equals("password")) {
??? ????password = c.getValue();
??? ???}

2 回復(fù) 有任何疑惑可以回復(fù)我~
#1

努力GOGO 提問者

非常感謝!牛人
2015-12-02 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

為什么輸入用戶名后登陸成功查看用戶信息用戶名變成了和密碼一樣的字符?

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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