diff --git a/javax-servlets/src/main/java/com/baeldung/servlets/CookieReader.java b/javax-servlets/src/main/java/com/baeldung/servlets/CookieReader.java index 133e729c33..13241e36f7 100644 --- a/javax-servlets/src/main/java/com/baeldung/servlets/CookieReader.java +++ b/javax-servlets/src/main/java/com/baeldung/servlets/CookieReader.java @@ -33,7 +33,7 @@ public class CookieReader { return Arrays.stream(request.getCookies()) .filter(c -> key.equals(c.getName())) .map(Cookie::getValue) - .findFirst(); + .findAny(); } } diff --git a/javax-servlets/src/main/java/com/baeldung/servlets/LoginServlet.java b/javax-servlets/src/main/java/com/baeldung/servlets/LoginServlet.java index ee4e73c956..f6e612a0d0 100644 --- a/javax-servlets/src/main/java/com/baeldung/servlets/LoginServlet.java +++ b/javax-servlets/src/main/java/com/baeldung/servlets/LoginServlet.java @@ -19,7 +19,7 @@ public class LoginServlet extends HttpServlet { Optional uiColor = cookieReader.readCookie("uiColor"); Optional userName = cookieReader.readCookie("userName"); - request.setAttribute("uiColor", uiColor.isPresent() ? uiColor.get() : "blue"); + request.setAttribute("uiColor", uiColor.orElse("blue")); if (!userName.isPresent()) { RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/login.jsp"); diff --git a/javax-servlets/src/main/java/com/baeldung/servlets/WelcomeServlet.java b/javax-servlets/src/main/java/com/baeldung/servlets/WelcomeServlet.java index dd66cb458e..262ad3061a 100644 --- a/javax-servlets/src/main/java/com/baeldung/servlets/WelcomeServlet.java +++ b/javax-servlets/src/main/java/com/baeldung/servlets/WelcomeServlet.java @@ -25,7 +25,7 @@ public class WelcomeServlet extends HttpServlet { if (!userName.isPresent()) { response.sendRedirect("/login"); } else { - request.setAttribute("uiColor", uiColor.isPresent() ? uiColor.get() : "blue"); + request.setAttribute("uiColor", uiColor.orElse("blue")); request.setAttribute("userName", userName.get()); request.setAttribute("sessionAttribute", request.getSession() .getAttribute("sampleKey"));