Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsp 生成将记住登录详细信息的cookie_Jsp_Cookies - Fatal编程技术网

Jsp 生成将记住登录详细信息的cookie

Jsp 生成将记住登录详细信息的cookie,jsp,cookies,Jsp,Cookies,编写下面的代码是为了让应用程序记住用户的登录详细信息,以避免再次打开登录页面时重新登录。但功能无法合并,每次都需要登录 <% String userName = request.getParameter("username"); String password = request.getParameter("password"); String rm_me = request.getParameter("rm_me"); String rm_uname = request.getParam

编写下面的代码是为了让应用程序记住用户的登录详细信息,以避免再次打开登录页面时重新登录。但功能无法合并,每次都需要登录

<%
String userName = request.getParameter("username");
String password = request.getParameter("password");
String rm_me = request.getParameter("rm_me");
String rm_uname = request.getParameter("rm_uname");
if (userName != null && password != null) {
if (rm_me != null) {
Cookie ckU = new Cookie("username", userName);
Cookie ckP = new Cookie("password", password);
response.addCookie(ckP);
} else {
if (rm_uname != null) {
Cookie ckU = new Cookie("username", userName);
}
}
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
if (cookies[i].getName().equals("username")) {
userName = cookies[i].getValue();
}
if (cookies[i].getName().equals("password")) {
password = cookies[i].getValue();
}
}
}
%>

您从未将Cookie CkU添加到响应中

读取后是否显示了该值?
顺便说一句,看看上面的评论,它们在安全性方面非常有趣。

@feeela我认为这是
为什么?
就像在
中一样,每次登录都需要重新键入-为什么?
:)将用户名和密码存储为纯文本cookie是不好的,即使使用了HTTPS。这使有权访问计算机的人能够确定密码,即使不是用户。当然,如果它是纯HTTP,它并没有那么糟糕。。。但不管怎样,这都是不好的。相关: