Author: markt Date: Sat Jan 8 22:27:26 2011 New Revision: 1056820 URL: http://svn.apache.org/viewvc?rev=1056820&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=21157 Write cookie before response might be committed
Modified: tomcat/trunk/webapps/docs/changelog.xml tomcat/trunk/webapps/examples/WEB-INF/classes/CookieExample.java Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1056820&r1=1056819&r2=1056820&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Sat Jan 8 22:27:26 2011 @@ -295,6 +295,10 @@ </subsection> <subsection name="Web applications"> <changelog> + <fix> + <bug>21157</bug>: Ensure cookies are written before the response is + commited in the Cookie example. Patch provided by Stefan Radzom. (markt) + </fix> <add> <bug>50294</bug>: Add more information to documentation regarding format of configuration files. Patch provided by Luke Meyer. (markt) Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/CookieExample.java URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/CookieExample.java?rev=1056820&r1=1056819&r2=1056820&view=diff ============================================================================== --- tomcat/trunk/webapps/examples/WEB-INF/classes/CookieExample.java (original) +++ tomcat/trunk/webapps/examples/WEB-INF/classes/CookieExample.java Sat Jan 8 22:27:26 2011 @@ -47,6 +47,15 @@ public class CookieExample extends HttpS HttpServletResponse response) throws IOException, ServletException { + + String cookieName = request.getParameter("cookiename"); + String cookieValue = request.getParameter("cookievalue"); + Cookie aCookie = null; + if (cookieName != null && cookieValue != null) { + aCookie = new Cookie(cookieName, cookieValue); + response.addCookie(aCookie); + } + response.setContentType("text/html"); PrintWriter out = response.getWriter(); @@ -89,11 +98,7 @@ public class CookieExample extends HttpS out.println(RB.getString("cookies.no-cookies")); } - String cookieName = request.getParameter("cookiename"); - String cookieValue = request.getParameter("cookievalue"); - if (cookieName != null && cookieValue != null) { - Cookie cookie = new Cookie(cookieName, cookieValue); - response.addCookie(cookie); + if (aCookie != null) { out.println("<P>"); out.println(RB.getString("cookies.set") + "<br>"); out.print(RB.getString("cookies.name") + " " --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org