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

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

cookie

為什么在user.jsp頁面無法輸出cookie,而且點記住登陸是無效的,明明和老師的代碼完全一樣啊!!!

login.jsp頁面

<%@ page language="java" import="java.util.*"

contentType="text/html; charset=utf-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme() + "://"

+ request.getServerName() + ":" + request.getServerPort()

+ path + "/";

%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<base href="<%=basePath%>">


<title>My JSP 'login.jsp' starting page</title>


<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->


</head>


<body>

<h1>登陸界面</h1>

<hr>

<%

String username = "";

String password = "";

Cookie[] cookies = request.getCookies();

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

for (Cookie cookie : cookies) {

if (cookie.getName().equals("username")) {

username=cookie.getValue();

}

if (cookie.getName().equals("password")) {

password=cookie.getValue();

}

}

}

%>

<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="isuseCooki" checked="checked" >十天內(nèi)記住登陸信息</td>

</tr>

<tr>

<td colspan="2"><input type="submit" value="登陸"></td>

</tr>

</table>

</form>

</body>

</html>


doLogin JSP頁面

<%@page import="org.apache.taglibs.standard.tag.common.core.ForEachSupport"%>

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

? <head>

? ? <base href="<%=basePath%>">

? ??

? ? <title>My JSP 'doLogin.jsp' starting page</title>

? ??

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0"> ? ?

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->


? </head>

??

? <body>

? ? <h1>登陸成功</h1>

? ? <hr>

? ? <%

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

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

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

? ? //把用戶名和密碼保存在cookie中

? ? String username=request.getParameter("username");

? ? String password=request.getParameter("password");

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

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

? ? //設(shè)置最大生存期限為10天

? ? nameCookie.setMaxAge(864000);

? ? wordCookie.setMaxAge(864000);

? ?

? ? response.addCookie(nameCookie);

? ? response.addCookie(wordCookie);

? ? }else{

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

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

? ? for(Cookie cookie:cookies){

? ? if(cookie.getName().equals("username")||cookie.getName().equals("password")){

? ? cookie.setMaxAge(0);

? ? response.addCookie(cookie);

? ? }

? ? }

? ? }

? ? }

? ??

? ??

? ? %>

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

? ??

? </body>

</html>

user.jsp頁面

<%@ page language="java" import="java.util.*"

contentType="text/html; charset=utf-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme() + "://"

+ request.getServerName() + ":" + request.getServerPort()

+ path + "/";

%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<base href="<%=basePath%>">


<title>My JSP 'user.jsp' starting page</title>


<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->


</head>


<body>

<h1>用戶信息</h1>

<hr>

<%

String username = "";

String password = "";

Cookie[] cookies = request.getCookies();

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

for (Cookie cookie : cookies) {

if (cookie.getName().equals("username")) {

username=cookie.getValue();

}

if (cookie.getName().equals("password")) {

password=cookie.getValue();

}

}

}

%>

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

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

</body>

</html>


正在回答

1 回答

doLogin.jsp 是否記住 用戶名密碼的字段用錯了。

? ? String[] strs=request.getParameterValues("inuseCooki");這句改成下面這樣:

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


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

單行道上 提問者

謝謝,問題已經(jīng)解決!
2017-02-09 回復(fù) 有任何疑惑可以回復(fù)我~
#2

Galeno_Lu 回復(fù) 單行道上 提問者

我也遇到了這種問題,你是怎么解決的呀?
2017-03-18 回復(fù) 有任何疑惑可以回復(fù)我~
#3

小短腿師姐 回復(fù) Galeno_Lu

我也遇到這個問題!?。。。。。。。。?!1
2017-03-19 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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