You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Dunkle, Ed" <Ed...@ameriserve.com> on 2000/05/05 00:04:10 UTC

RE: No application cookies are getting sent to browser (Redirect drops cookies)

OK, this is the same behavior we get with WebShpere 2.0  (3.2 may be
fixed...)
If you set the cookie in the ContentType and then redirect, the cookies
never get sent to the client:

	response.setContentType("text/html\nSet-Cookie: hot.name=" +
userName + "; path=/; expires=" + cookieDate + "\nSet-Cookie: hot.regnum=" +
registrationNumber + "; path=/; expires=" + cookieDate);
	response.sendRedirect(somePage);

So I have to redirect by sending output like this:
	ServletOutputStream p = response.getOutputStream();
	p.println("<HTML><HEAD>");
	p.println("<meta http-equiv=\"REFRESH\" content=\"0; URL=" +
somePage + "\">");
	p.println("</HEAD></HTML>");
	p.flush();
	p.close();

Is this behavior dictated by the spec?  I noticed it requires the buffer to
be cleared when sendRedirect() is called.

Thanks,
Ed


-----Original Message-----
From: Dunkle, Ed 
Sent: Thursday, May 04, 2000 2:10 PM
To: 'tomcat-user@jakarta.apache.org'
Subject: No application cookies are getting sent to browser


Is there some configuration setting to activate application level cookies?

I have servlet code that works in WebSphere (and I believe it used to work
in Apache/JServ but we don't use that anymore) for writing cookies.  Under
Tomcat (with IIS if that matters) I get a JSession cookie but it doesn't
even try to send my application cookies.

Any ideas?


Here's the code:

public void writeCookies(HttpServletResponse response, String userName,
String registrationNumber, Date expiryDate) {
	Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
	expiry.setTime(expiryDate);
	DateFormat df = DateFormat.getDateTimeInstance();
	SimpleDateFormat sdf = null;
	String cookieDate = null;
		
	try {
		sdf = (SimpleDateFormat) df;
		sdf.setCalendar(expiry);
		sdf.applyPattern("EEE, dd-MMM-yyyy hh:mm:ss zzz");
		cookieDate = sdf.format(expiry.getTime());
	} catch (ClassCastException cce) {
		cce.printStackTrace();
	}
	
	response.setContentType("text/html\nSet-Cookie: hot.name=" +
userName + "; path=/; expires=" + cookieDate + "\nSet-Cookie: hot.regnum=" +
registrationNumber + "; path=/; expires=" + cookieDate);
}