Hello all,

My servlet stopped working when I moved from
Tomcat4.0.6 to Tomcat5.5.9. After investigating the
problem, it turns out that if the
HttpServletResponse.setContentLength() method is
called, subsequent calls (e.g. setHeader(),
addHeader(),addCookie()..etc) into the
HttpServletResponse object are completely ignored (or
discarded  from underneath!). 

For example, if I do the following in my service
method: (httpResponse is defined HttpServletResponse)

httpResopnse.setStatus(204); // I tried 200 and got
the same problem, I guess status code doesn't play
part in this problem.
httpResponse.setHeader("header1","value1"); //works
httpResponse.setHeader("header2","value2"); //works
httpResponse.setContentLength(0); // nothing gets set 
on the response object after this point
httpResponse.setHeader("header3","value3"); //
ignored!
httpResponse.addCookie(new
Cookie("JSESSIONID","myCookie")); // ignored!

My proxy shows that header1 and header2 are set
correctly but header3 and my cookie are missing! It
seems that it expects setContentLength is the last
method to be set on the response object and any method
call after that on the resopnse object gets ignored
(or discarded)

I have attached a simple servlet that reproduces this
problem.

My question: is this an expected behaviour? I checked
the http specs and the servlet 2.4 specs but nothing
specified this behaviour. Can someone please explain
if this is the expected behaviour (and why?
specs..etc) or it's a bug?

Thanks in advance,



                
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* $Id: HelloWorldExample.java,v 1.3 2004/03/18 16:40:33 jfarcand Exp $
 *
 */

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 * The simplest possible servlet.
 *
 * @author James Duncan Davidson
 */

public class HelloWorldExample extends HttpServlet {


    public void service(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
       try
       {
	    response.setStatus(204); //regardless of the status
	    response.setContentType("text/html");
	    // header1 and header 2 will be set
	    response.setHeader("Header1","value1");
	    response.addHeader("Header2","value2");
	    response.setContentLength(0);
	    // header3 and the cookie will be dropped
	    response.setHeader("Header3","value3");
	    response.addCookie(new Cookie("JSESSIONID","myCookieValue"));

       }catch(Exception e){
	    System.out.println("Exception occured: "+e.getMessage());
       }
    }
}




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to