New Cookies aren't Showing Up with Java Servlets/Tomcat after removing Cookies from Chrome

Viewed 90

I am new at Java. I saw some responses but didn't quite got it, something with doFilter or Wrapper. I am inside a @WebServlet running this code after cleaning the Chrome Cookies, but it always print 'Sorry', although I just created a new Cookie.

    @WebServlet(name = "Servlet2",
            urlPatterns = "/welcome")
    public class Servlet2 extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//some code here
            Cookie cookie = new Cookie("Session-Cookie-", "Cookie-Value-S");
            response.addCookie(cookie);
            Cookie[] cookies = request.getCookies();
            if (cookies == null) {
                System.out.println("SORRY");
            } else {
                System.out.println("OHYEAH");
            }
//some code here
        }
    }

How can I implement a code to deal with this issue? Thanks in advance.

0 Answers
Related