Servlet refactor (#3851)
This commit is contained in:
parent
d70fbdc273
commit
94fc6997fe
|
@ -33,7 +33,7 @@ public class CookieReader {
|
|||
return Arrays.stream(request.getCookies())
|
||||
.filter(c -> key.equals(c.getName()))
|
||||
.map(Cookie::getValue)
|
||||
.findFirst();
|
||||
.findAny();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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"));
|
||||
|
|
Loading…
Reference in New Issue