I have to create a new cookie if the cookie does not already exist. If the cookie already exist, then I should not override it, but just return it.
How can I verify whether the cookie exists or not? I have looked at javax.servlet.http.Cookie API, but I couldn’t find any clues.
How can I retrieve and validate existing cookies?
You can get all cookies by
HttpServletRequest#getCookies().Note that this already contains only valid (non-expired) cookies. The browser namely already won’t send expired cookies along the request.