tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hassan Schroeder" <hassan.schroe...@gmail.com>
Subject Re: http header setting problem in servlet
Date Tue, 24 Apr 2007 16:45:37 GMT
On 4/24/07, Huseyin Sinecan <hsinecan@yahoo.com> wrote:

> Thanks for the answer.. Here is the complete code of doGet method:

For clarity, here's my entire adaptation of your code:
-----------------------------------------------------------------------------------
package com.example.test;

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

public class Something extends HttpServlet {

		protected void doGet(HttpServletRequest theRequest,
HttpServletResponse theResponse) throws ServletException, IOException
{

       theResponse.reset();
       theResponse.resetBuffer();

       theResponse.setHeader("Request Version", "HTTP/1.1");
       theResponse.setStatus(200);
       theResponse.setHeader("Date", "Wed, 18 Apr 2007 09:24:04 GMT");
       theResponse.setHeader("Server", "Tomcat");
       theResponse.addCookie(theRequest.getCookies()[0]);
       theResponse.setHeader("pragma", "no-cache"); // HTTP 1.0
       theResponse.setHeader("Cache-Control", "no-cache"); // HTTP 1.1
       theResponse.setHeader("Expires", "Mon, 26 Jul 1997 05:00:00
GMT"); // a past date
       theResponse.setDateHeader("Last-Modified", (new
java.util.Date()).getTime());
       theResponse.setHeader("Connection", "close");
       theResponse.setContentType("text/plain");

       theResponse.flushBuffer();

       String aResponse = "what now?";

       PrintWriter aPrintWriter = theResponse.getWriter();
       aPrintWriter.write(aResponse);
       aPrintWriter.flush();

   }
}
-----------------------------------------------------------------------------------

And here's the result from LiveHTTPHeaders -- hopefully that'll give
you something to go on...
-----------------------------------------------------------------------------------
HTTP/1.x 200 OK
Date: Tue, 24 Apr 2007 16:32:06 GMT
Server: foo/bar <= ignore, that's my own setting on the Connector
Set-Cookie: JSESSIONID=746B06EB8432B81A63CBA04725E2F131
Pragma: no-cache
Cache-Control: no-cache
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Tue, 24 Apr 2007 16:32:06 GMT
Connection: close
Content-Type: text/plain
Transfer-Encoding: chunked
-----------------------------------------------------------------------------------

HTH!
-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message