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 16:08:41 GMT
This works.


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();

        response.addCookie( new Cookie("foo", "bar") );
        response.flushBuffer();

        RequestDispatcher rd
            = getServletContext().getRequestDispatcher(
"/thePageThatShowsTheCookie.jsp"  );

        rd.include(request, response);
        out.close();

    }

}

/***************************/
<html>
<b>Cookies:</b><br>
<%
Cookie c[] = request.getCookies();
for (int i = 0; i < c.length; i++)
{
%>
name: <%= c[i].getName() %> value: <%= c[i].getValue() %><br>
<%
}
%>
</html>


Tom Samplonius wrote:

> On Mon, 7 Aug 2000, Mason Jones wrote:
>
> > Hello, all... I'm doing something pretty straightforward, trying
> > to add a cookie to a servlet response before doing a redirect
> > to a jsp page. But the cookie's simply not being set. Hope
> ...
>
>   This has been discussed before.  I don't believe that browsers will
> accept an cookie and a redirect in the same response.
>
> Tom


Mime
View raw message