Sorry for my English.

When user authentication cookies created: There main page - index.jsp There is a home page, which lists the following authorization - home.jsp Any filter that is tied to home.jsp. Authorization takes place in the filter (class goes through a connection to the database), and if all is well established that the cookies and then everything goes to home.jsp. In home.jsp at the beginning there is a check on the cookies and if they have the user stays on the page, if not doing Redirect on index.jsp.

The essence of the problem is that after leaving the Filter cookies there. After it goes to check home.jsp sootvetstvenno and it redirects to the index but already there appear cookies and redirects it to the home. In the same way if you do it all through Servlen

The question is how to treat? I know it's an option to add cookies already on the home page itself.

The code added to the cookie:

Java Code:
Cookie cookie = new Cookie("login", Login);

cookie.setMaxAge(CookiesTime);

res.addCookie(cookie);
Checking for cookies in home.jsp
Java Code:
<%
    String login = "";
    String hash = "";

    Cookie[] cookies = request.getCookies();
    for (Cookie cookie : cookies) {
        if (cookie.getName().equals("badAuth")) {
            System.err.println("home.jsp -> Found badAuth!");

            response.sendRedirect("index");
            return;
        } else {
            if (cookie.getName().equals("login")) {
                System.out.println("home.jsp -> Found login");
                login = cookie.getValue();
            }
            if (cookie.getName().equals("hash")) {
                System.out.println("home.jsp -> Found hash");
                hash = cookie.getValue();
            }
        }
    }

    dbConnect connect = new dbConnect();

    if (!login.equals("") && !hash.equals("")) {
        if (connect.checkHash(login, hash)) {

            int roleNum = connect.checkUserRole(login, dbConnect.ROLE_USER);
            if(roleNum == 1 || roleNum == 2) {
                request.setAttribute("role", roleNum);

                ArrayList<Link> linkArr = connect.GetLinks(connect.getId(login));
                request.setAttribute("linkArr", linkArr);
            } else {
                response.sendRedirect("index");
                return;
            }
        }
    } else {
        response.sendRedirect("index");
        return;
    }
%>