tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Weiland <sweil...@viatraining.com>
Subject Re: response.addCookie() problem
Date Tue, 08 Aug 2000 22:30:28 GMT
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


Mime
View raw message