/** * Created with IntelliJ IDEA. * * @Author: * @Date: 2021/11/11/19:16 * @Des: */ public class LoginServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
String name = req.getParameter("userName");
String pwd = req.getParameter("pwd");
String mem = req.getParameter("m");
System.out.println("名字:"+name+",密码:"+pwd+",是否记住密码:"+mem);
if (name.equals("1") && pwd.equals("1") && name !="" && pwd != ""){
System.out.println("账号密码都为admin,登录成功!");
Cookie u = null;
Cookie p = null;
Cookie m = null;
//记住密码 把数据存入cookie中
u = new Cookie("u",name);
p = new Cookie("p",pwd);
if ("1".equals(mem)){
System.out.println("记住密码 把数据存入cookie中");
u = new Cookie("u",name);
p = new Cookie("p",pwd);
m = new Cookie("m",mem);
System.out.println("loginservlet43行mem"+mem);
//设置保存时间 单位是秒
u.setMaxAge(60);
p.setMaxAge(60);
m.setMaxAge(60);