On Tue, 18 May 1999, Guenther Wieser wrote:

> I had the same problems when using NS 4.X.
> Everything works fine now, as I use StringBuffer everywhere and the
> write the content once (hope that this is the reason why it works now!).
>
> Mike Varley wrote:
> > 
> > I am trying to use the session tracking API with JServ, but have run
> > into a problem in that sessions don't get tracked properly.  I can run
> > the servlets on the Java Web server and they track perfectly.
[snip]
> > I read in the bug report:
> > ------------------
> > Due to the same protocol restrictions, headers are sent as soon as something
> > is written on the output, preventing any change on them (sessions, cookies).
> > To
> > avoid this, you may buffer your output in your servlet and send it
> > afterwards.
> > ------------------
> > 
> > What does this mean?  Should I be piping everything through a
> > BufferedWriter, or a StringBuffer, and then doing a flush() in order to get
> > session tracking working properly?
[snip]

What it means is that you *must* send headers (which include cookies) 
before you send any part of the page.  You can do this either by buffering
the page or by being sure to request the new session before you've sent
anything back. 

Using a StringBuffer, as Guenther indicated, is one possible way to
address this (and yes, I think that's why you were having problems
before).

Using a buffered output stream would work so long as you only output a
little bit of data before you sent the headers.  But generally, buffered
output streams will start sending data eventually, on their own, whether
or not you call flush(). 

hth --

Ed



-- --------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
READ THE FAQ!!!!     <http://java.apache.org/faq/>
Archives and Other:  <http://java.apache.org/main/mail.html/>
Problems?:           [EMAIL PROTECTED]

Reply via email to