cookie实现不了一些问题

实现了一个简单的登录界面,下次登录时会自动显示用户名,可是显示不出来,不知道哪里错了,求解答

login.jsp:

<body>
    <%!
    String uname;
    %>
    <%
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals("uname")) {
                uname = cookie.getValue();
            }
        }
    %>
    <form action="check.jsp" method="post">
        用户名:<input type="text" name="uname" value="<%=(uname==null?"":uname)%>"><br /> 
            密码:<input type="password" name="pwd"><br> 
            <input type="submit"value="登录">
    </form>
</body>

check.jsp:

<body>
    <%
        request.setCharacterEncoding("utf-8");
        String name = request.getParameter("uname"); 
        String pwd = request.getParameter("upwd");
        //加入到cookie中
        Cookie cookie=new Cookie("name",name);
        response.addCookie(cookie);
        response.sendRedirect("a.jsp");//空的jsp,
    %>
</body>

发布之后:

https://blog.csdn.net/tTU1EvLDeLFq5btqiK/article/details/88361192