Return-Path: Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 5059 invoked from network); 9 Jul 2000 19:53:49 -0000 Received: from lukla.sun.com (192.18.98.31) by locus.apache.org with SMTP; 9 Jul 2000 19:53:49 -0000 Received: from centralmail1.Central.Sun.COM ([129.147.62.10]) by lukla.Sun.COM (8.9.3+Sun/8.9.3) with ESMTP id NAA07690 for ; Sun, 9 Jul 2000 13:53:48 -0600 (MDT) Received: from esun1as-mm. (esun1as-mm.Central.Sun.COM [129.147.34.144]) by centralmail1.Central.Sun.COM (8.9.3+Sun/8.9.3/ENSMAIL,v1.7) with SMTP id NAA08971 for ; Sun, 9 Jul 2000 13:53:48 -0600 (MDT) Received: from eng.sun.com by esun1as-mm. (SMI-8.6/SMI-SVR4) id NAA18479; Sun, 9 Jul 2000 13:54:48 -0600 Message-ID: <3968D862.91BEC60@eng.sun.com> Date: Sun, 09 Jul 2000 12:54:10 -0700 From: "Craig R. McClanahan" X-Mailer: Mozilla 4.72 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: tomcat-user@jakarta.apache.org Subject: Re: cookies References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit See interspersed comment below. Nabih Abu Abid wrote: > Here is the source code for the servlet > public class CookieDetector extends HttpServlet { > > String probeName = "CookieDetector.probe"; > > public void doGet(HttpServletRequest req, HttpServletResponse res) > throws IOException, ServletException > { > log("doGet"); > System.out.println("doGet"); > Cookie cookie; > int port = req.getServerPort(); > String self = req.getScheme() + "://" + req.getServerName() + > (port == 80 ? "" : ":"+port) + req.getServletPath(); > log("self = " + self); > System.out.println("self = " + self); > String phase = req.getParameter("phase"); > log("phase = " + phase); > System.out.println("phase = " + phase+" probName="+probeName); > if (phase == null) { > cookie = new Cookie(probeName, req.getServletPath()); > cookie.setComment("Will this get dropped?"); > cookie.setMaxAge(-1); > cookie.setPath(req.getServletPath()); > res.addCookie(cookie); > System.out.println("CAll sendRedirect"); > res.sendRedirect( self + "?phase=check" ); > There is a bug in Tomcat 3.1 that causes it to erase any cookies or headers you have set when you use response.sendRedirect(). This is fixed in the current Tomcat 3.2 beta. > } > else if (phase.equals("check")) { > Cookie[] cookies = req.getCookies(); > boolean hasCookies = false; > if (cookies != null) { > for (int i = 0; i < cookies.length; i++) { > System.out.println("cookie " + cookies[i].getName() + "=" + > cookies[i].getValue()); > log("cookie " + cookies[i].getName() + "=" + cookies[i].getValue()); > if (cookies [i].getName ().equals (probeName)) { > if (cookies[i].getValue().equals(req.getServletPath())) > { > hasCookies = true; > break; > } > } > } > } > String where; > String message = ""; > if (hasCookies) { > where = getInitParameter("urlCookies"); > if (where == null || where.equals("")) { > where = null; > message = "Client allows cookies"; > } > } > else { > where = getInitParameter("urlNoCookies"); > if (where == null || where.equals("")) { > where = null; > message = "Client does not allow cookies"; > } > } > System.out.println("where="+where); > if (where == null) { > res.setContentType("text/plain"); > res.getWriter().println(message); > } > else { > res.sendRedirect(where); > } > } > } > } > > -----Original Message----- > From: Erik Tennant [mailto:lists@webpd.com] > Sent: Thursday, July 06, 2000 6:16 PM > To: tomcat-user@jakarta.apache.org > Subject: Re: cookies > > Are phase 1 and phase 2 different requests? You can't set a cookie and > then expect to read it in the same request. Maybe you can provide a little > more information. > > -Erik > > At 03:13 PM 7/6/00 +0200, you wrote: > >Hi, > >I'm running Apache and Tomcat as a servlet runner. When i run a Cookie > >detector servlet which builds a new cookie at phase 1 and then checks the > >cookie at phase 2 i get null value, meaning the cookie was not build???? > > > >If you've faced this problem before and a solution i will be very > gratefull. > >thanks > > > > Craig McClanahan