tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mason Jones <ma...@clipshow.com>
Subject Re: response.addCookie() problem
Date Tue, 08 Aug 2000 22:46:40 GMT

I'll try that change; one possibility is that even setting path
to "/" will prepend the webapp root. Because I know that
when I do the getRequestDispatcher() call, the webapp root
is prepended to the URL that's passed in. For example, if
I do a getRequestDispatcher("/test.jsp") and my webapp is
under "/javatest", the URL that it's actually sent to is
"/javatest/test.jsp". I'll check it out; I'll also make sure I have
the latest tomcat version, in case it is a bug.

Steve Weiland wrote:
>Perhaps this fellow.
>
>import java.io.*;
>import javax.servlet.*;
>import javax.servlet.http.*;
>
>public class CookieThing extends HttpServlet
>{
>
>     public void doGet(HttpServletRequest request, HttpServletResponse
>response)
>         throws IOException, ServletException
>     {
>
>         response.setContentType("text/html");
>         PrintWriter out = response.getWriter();
>
>         Cookie c = new Cookie("foo", "bar");
>         c.setPath("/");    // here
>
>         response.addCookie( c );
>         response.flushBuffer();
>
>         RequestDispatcher rd
>             = getServletContext().getRequestDispatcher(
>"/thePageThatShowsTheCookie.jsp"  );
>
>         rd.include(request, response);
>         out.close();
>
>     }
>
>}
>
>
>
>
>"Craig R. McClanahan" wrote:
>
> > Mason Jones wrote:
> >
> > >
> > > Thanks for the suggestion on this. It actually turns out that
> > > what I was doing was in working, but when I used a page
> > > outside my webapp to display the cookies, they weren't
> > > showing up. I'm still not sure why that is, since the cookies
> > > should obviously be tied to the domain name, not the webapp.
> > >
> >
> > Actually, that is not necessarily true.  When you create a cookie, you
> > can use the "path" property to say that this cookie should only be sent
> > back if the domain matches *and* the beginning of the request URI
> > matches the specified path.  For example, Tomcat uses this to ensure
> > that the session ID cookie (which always has the same cookie name)
> > always goes back to the correct app.
> >
> > >
> > > (I've got a simple little page to display cookies which uses
> > > PHP, but it's not seeing the cookies that are being set by the
> > > tomcat servlet...weird. Anyone have ideas why this is?)
> > >
> >
> > One possibility is if you are setting cookies and doing a
> > sendRedirect(), and are running Tomcat 3.1, you've run into a bug.  Try
> > it with Tomcat 3.2beta2.
> >
> > >
> > > Thanks for the help.
> > >
> >
> > Craig McClanahan


________________________________________
   Mason Jones              mason(at)clipshow.com
   Director of Software Development
   ClipShow, Inc.            www.clipshow.com
   (650) 696-3164           fax (650) 696-3267


Mime
View raw message