I can get cookie in JSP like this:
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
//work with cookies
}
}
But I wonder if I can get it with jsp:useBean (or something else)? May be like this:
<jsp:useBean id="myCookie" class="javax.servlet.http.Cookie" scope="request" beanName="cookieName"/>
...
<div class="${myCookie.value == "true" ? "class1" : "class2"}"></div>
Thx for your answers!
use jsp expression language it has implicit map of cookies. may be it can resolve your issue.
${cookie['name']}
hope this one could help you to get name and value of your cookie
${cookie['cookiename'].getName()}
${cookie['cookiename'].getValue()}
OR
${cookie.cookiename.getName()}
${cookie.cookiename.getValue()}
OR
${cookie.<cookiename>.name}
${cookie.<cookiename>.value}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With