Servlet refactor (#3851)

This commit is contained in:
Grzegorz Piwowarek 2018-03-19 20:02:28 +01:00 committed by maibin
parent d70fbdc273
commit 94fc6997fe
3 changed files with 3 additions and 3 deletions

View File

@ -33,7 +33,7 @@ public class CookieReader {
return Arrays.stream(request.getCookies())
.filter(c -> key.equals(c.getName()))
.map(Cookie::getValue)
.findFirst();
.findAny();
}
}

View File

@ -19,7 +19,7 @@ public class LoginServlet extends HttpServlet {
Optional<String> uiColor = cookieReader.readCookie("uiColor");
Optional<String> 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");

View File

@ -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"));