Cookies are not getting added to the browser when the code adding the cookie is part of a fragment of JSP (includes.jsp) included in the primary page (main.jsp) via JSP:INCLUDE.
The code works fine when it is part of the primary page (main.jsp). However, I need to add the cookie via the fragment since that fragment is used in dozens of pages where I want the cookie to get added.
Note: The jsp:include is part of the header section of main.jsp (the fragment also adds a number of javascript and css references)
Here is the snippet:
Cookie cookie = new Cookie ("test","test cookie");
cookie.setMaxAge(365 * 24 * 60 * 60);
cookie.setPath("/");
response.addCookie(cookie2);
The above works fine when it is part of the main.jsp but doesn't work when it is part of the fragment added to main.jsp via . it is almost as if the response object is being reset after the fragment is rendered.