利用cookie储存用户名和密码保证下次自动登录利用session保存用户名并在登录成功页面输出用户名和密码
登陆页面代码
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2019/11/18
Time: 8:46
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>登录</title>
</head>
<body>
<form name="fl" action="SaveInfoTOCookieServlet" method="post">
用户名:<input type="text" name="username" value="${username}">
<br>
密 码:<input type="password" name="password" value="${password}">
<br>
记住登录信息:<input type="checkbox" name="saveInfo" value="saved">
<br>
<input type="submit" value="登录">
</form>
</body>
</html>
编写登录判断页面
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servle