Servlet refactor (#3851)
This commit is contained in:
parent
d70fbdc273
commit
94fc6997fe
|
@ -33,7 +33,7 @@ public class CookieReader {
|
||||||
return Arrays.stream(request.getCookies())
|
return Arrays.stream(request.getCookies())
|
||||||
.filter(c -> key.equals(c.getName()))
|
.filter(c -> key.equals(c.getName()))
|
||||||
.map(Cookie::getValue)
|
.map(Cookie::getValue)
|
||||||
.findFirst();
|
.findAny();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class LoginServlet extends HttpServlet {
|
||||||
Optional<String> uiColor = cookieReader.readCookie("uiColor");
|
Optional<String> uiColor = cookieReader.readCookie("uiColor");
|
||||||
Optional<String> userName = cookieReader.readCookie("userName");
|
Optional<String> userName = cookieReader.readCookie("userName");
|
||||||
|
|
||||||
request.setAttribute("uiColor", uiColor.isPresent() ? uiColor.get() : "blue");
|
request.setAttribute("uiColor", uiColor.orElse("blue"));
|
||||||
|
|
||||||
if (!userName.isPresent()) {
|
if (!userName.isPresent()) {
|
||||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/login.jsp");
|
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/login.jsp");
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class WelcomeServlet extends HttpServlet {
|
||||||
if (!userName.isPresent()) {
|
if (!userName.isPresent()) {
|
||||||
response.sendRedirect("/login");
|
response.sendRedirect("/login");
|
||||||
} else {
|
} else {
|
||||||
request.setAttribute("uiColor", uiColor.isPresent() ? uiColor.get() : "blue");
|
request.setAttribute("uiColor", uiColor.orElse("blue"));
|
||||||
request.setAttribute("userName", userName.get());
|
request.setAttribute("userName", userName.get());
|
||||||
request.setAttribute("sessionAttribute", request.getSession()
|
request.setAttribute("sessionAttribute", request.getSession()
|
||||||
.getAttribute("sampleKey"));
|
.getAttribute("sampleKey"));
|
||||||
|
|
Loading…
Reference in New Issue