You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by neal <ne...@yahoo.com> on 2002/11/26 20:17:54 UTC

Response.ContentType - not always setting contentType in Header

Does anyone know of a reason why response.setContentType() would only
sometimes set my content type?

I have a single control servlet which sets content type explicitly

response.setContentType("text/html");

just before it opens an outputStream and writes an XSLT transformation to
out.  For 70% of my pages the contentType is correct.  For 30% of them (even
the pages otherwise work perfectly fine) the header info is messed up. There
is no contentType specified and contentLenght is 0.  Very strange. In these
pages (their control classes I do not do anything specific to the response
object that is any different from the other pages.  In the XsLTs I specify
output as HTML on all the pages.  Very confusing.

Any thoughts as to why this might happen or how to correct it?  I think it
may be causing me search engine indexing problems.

Thanks.
Neal 

Re: Response.ContentType - not always setting contentType in Header

Posted by Jacob Kjome <ho...@visi.com>.
Hello neal,

I've notice that in a filter I have that the content length is
sometimes zero.  This never happens the first time a browser requests
a particular page but will happen each time after that if the user
hits "reload".  The browser just seems to reload from its own cache.
The browser sends the request and the server must be saying that the
content hasn't changed or something so it sends back a response with
a length of zero.  If I do a shift+reload, the the response is as I
would expect it.

The reason why I brought that up is the same thing may be happening
for you.  Maybe when the server determines that the content hasn't
changed it sends back a zero length response and, since the response
contains no content to render, the content-type isn't set?

Jake

Tuesday, November 26, 2002, 1:17:54 PM, you wrote:

n> Does anyone know of a reason why response.setContentType() would only
n> sometimes set my content type?

n> I have a single control servlet which sets content type explicitly

n> response.setContentType("text/html");

n> just before it opens an outputStream and writes an XSLT transformation to
n> out.  For 70% of my pages the contentType is correct.  For 30% of them (even
n> the pages otherwise work perfectly fine) the header info is messed up. There
n> is no contentType specified and contentLenght is 0.  Very strange. In these
n> pages (their control classes I do not do anything specific to the response
n> object that is any different from the other pages.  In the XsLTs I specify
n> output as HTML on all the pages.  Very confusing.

n> Any thoughts as to why this might happen or how to correct it?  I think it
n> may be causing me search engine indexing problems.

n> Thanks.
n> Neal 



-- 
Best regards,
 Jacob                            mailto:hoju@visi.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Response.ContentType - not always setting contentType in Header

Posted by neal <ne...@yahoo.com>.
Micael,

yeah, here's the code I've written that I believe to be applicable.  The
controlServlet (the first snippet) sets the contentType, gets the out and
writes to the writer, the output of the XSLT transformation.  This is done
by calling transformTOWriter (which is in a dff't class).  Note, that I have
provided the overridden version of this method as well so you can see how
the one applicable to the first snippet basically just aliases to the 3 arg
version of the mehtod.

This seems to work with most classes just not all.  :(

In regard to a couple of questions as to whether the contentLength was set
to 0 upon refreshing - na ... its this way the first time its called and
even if I do an explicit refresh.  The content comes out fine, displays
fine, but the lenght is still 0 and the contentType is not there.  FYI,
here's the tool I'm using to view this info:

http://www.searchengineworld.com/cgi-bin/sim_spider.cgi


<<<CODE REFERRED TO ABOVE>>>

//Preperare & publish
 response.setContentType("text/html");
 PrintWriter out = response.getWriter();
 XslTool xt = new XslTool();
 xt.transformToWriter(xml, xsl, out, xslParams);


   public void transformToWriter(Document xml, Transformer xsl, Writer out,
Hashtable parameters)
    throws TransformerException {
      if (parameters != null) {
         for (Enumeration e = parameters.keys() ; e.hasMoreElements() ;) {
            String key = (String)e.nextElement();
            xsl.setParameter(key, (String)parameters.get(key));
         }
      }
      transformToWriter(xml,xsl,out);
   }

   /** Transform specified DOM against specified transformed and out to a
writer. */
  public void transformToWriter(Document xml, Transformer xsl, Writer out)
    throws TransformerException {

        xsl.transform(new DOMSource(xml), new StreamResult(out));
   }

-----Original Message-----
From: micael [mailto:caraunltd@harbornet.com]
Sent: Tuesday, November 26, 2002 11:48 AM
To: Tomcat Users List
Subject: RE: Response.ContentType - not always setting contentType in
Header


Can you provide the relevant code from one that does not work and one that
does work?  Or, would you have to kill me if you did that?

At 11:35 AM 11/26/2002 -0800, you wrote:
>Definitive classes.  And I have (and still am) going through the XSLT and
>the page classses (the classes that the control servlet calls specific to
>the requested page) with a fine tooth comb.  The only thing that the 3
>problem pages seem to have in common that I have not yet eliminated is that
>they (a) read from the request header info, and (b) do a couple of
redirects
>if needed based upon that request header info.  But those conditions should
>not be applicable to a simple request and thus should not affect the
output.
>In fact, the status code is 200 (not 302 in the case of a redirect).  So
>then, I guess the only really difference that I'm seeing so far is that
they
>read from the request header.  but I can't imagine that this would make a
>difference.  :(
>
>Thanks.
>Neal
>
>-----Original Message-----
>From: micael [mailto:caraunltd@harbornet.com]
>Sent: Tuesday, November 26, 2002 11:27 AM
>To: Tomcat Users List
>Subject: Re: Response.ContentType - not always setting contentType in
>Header
>
>
>Is it seemingly random or is it definitive classes Neal?
>
>At 11:17 AM 11/26/2002 -0800, you wrote:
> >Does anyone know of a reason why response.setContentType() would only
> >sometimes set my content type?
> >
> >I have a single control servlet which sets content type explicitly
> >
> >response.setContentType("text/html");
> >
> >just before it opens an outputStream and writes an XSLT transformation to
> >out.  For 70% of my pages the contentType is correct.  For 30% of them
>(even
> >the pages otherwise work perfectly fine) the header info is messed up.
>There
> >is no contentType specified and contentLenght is 0.  Very strange. In
these
> >pages (their control classes I do not do anything specific to the
response
> >object that is any different from the other pages.  In the XsLTs I
specify
> >output as HTML on all the pages.  Very confusing.
> >
> >Any thoughts as to why this might happen or how to correct it?  I think
it
> >may be causing me search engine indexing problems.
> >
> >Thanks.
> >Neal
> >
> >--
> >To unsubscribe, e-mail:
><ma...@jakarta.apache.org>
> >For additional commands, e-mail:
><ma...@jakarta.apache.org>
>
>Micael
>
>-------------------------------------------------------
>
>This electronic mail  transmission and any accompanying documents contain
>information belonging to the sender which may be confidential and legally
>privileged.  This information is intended only for the use of the
>individual or entity to whom this electronic mail transmission was sent as
>indicated above. If you are not the intended recipient, any disclosure,
>copying, distribution, or action taken in reliance on the contents of the
>information contained in this transmission is strictly prohibited.  If you
>have received this transmission in error, please delete the message.  Thank
>you
>
>
>
>--
>To unsubscribe, e-mail:
><ma...@jakarta.apache.org>
>For additional commands, e-mail:
><ma...@jakarta.apache.org>
>
>
>--
>To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
>For additional commands, e-mail:
<ma...@jakarta.apache.org>

Micael

-------------------------------------------------------

This electronic mail  transmission and any accompanying documents contain
information belonging to the sender which may be confidential and legally
privileged.  This information is intended only for the use of the
individual or entity to whom this electronic mail transmission was sent as
indicated above. If you are not the intended recipient, any disclosure,
copying, distribution, or action taken in reliance on the contents of the
information contained in this transmission is strictly prohibited.  If you
have received this transmission in error, please delete the message.  Thank
you



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Response.ContentType - not always setting contentType in Header

Posted by micael <ca...@harbornet.com>.
Can you provide the relevant code from one that does not work and one that 
does work?  Or, would you have to kill me if you did that?

At 11:35 AM 11/26/2002 -0800, you wrote:
>Definitive classes.  And I have (and still am) going through the XSLT and
>the page classses (the classes that the control servlet calls specific to
>the requested page) with a fine tooth comb.  The only thing that the 3
>problem pages seem to have in common that I have not yet eliminated is that
>they (a) read from the request header info, and (b) do a couple of redirects
>if needed based upon that request header info.  But those conditions should
>not be applicable to a simple request and thus should not affect the output.
>In fact, the status code is 200 (not 302 in the case of a redirect).  So
>then, I guess the only really difference that I'm seeing so far is that they
>read from the request header.  but I can't imagine that this would make a
>difference.  :(
>
>Thanks.
>Neal
>
>-----Original Message-----
>From: micael [mailto:caraunltd@harbornet.com]
>Sent: Tuesday, November 26, 2002 11:27 AM
>To: Tomcat Users List
>Subject: Re: Response.ContentType - not always setting contentType in
>Header
>
>
>Is it seemingly random or is it definitive classes Neal?
>
>At 11:17 AM 11/26/2002 -0800, you wrote:
> >Does anyone know of a reason why response.setContentType() would only
> >sometimes set my content type?
> >
> >I have a single control servlet which sets content type explicitly
> >
> >response.setContentType("text/html");
> >
> >just before it opens an outputStream and writes an XSLT transformation to
> >out.  For 70% of my pages the contentType is correct.  For 30% of them
>(even
> >the pages otherwise work perfectly fine) the header info is messed up.
>There
> >is no contentType specified and contentLenght is 0.  Very strange. In these
> >pages (their control classes I do not do anything specific to the response
> >object that is any different from the other pages.  In the XsLTs I specify
> >output as HTML on all the pages.  Very confusing.
> >
> >Any thoughts as to why this might happen or how to correct it?  I think it
> >may be causing me search engine indexing problems.
> >
> >Thanks.
> >Neal
> >
> >--
> >To unsubscribe, e-mail:
><ma...@jakarta.apache.org>
> >For additional commands, e-mail:
><ma...@jakarta.apache.org>
>
>Micael
>
>-------------------------------------------------------
>
>This electronic mail  transmission and any accompanying documents contain
>information belonging to the sender which may be confidential and legally
>privileged.  This information is intended only for the use of the
>individual or entity to whom this electronic mail transmission was sent as
>indicated above. If you are not the intended recipient, any disclosure,
>copying, distribution, or action taken in reliance on the contents of the
>information contained in this transmission is strictly prohibited.  If you
>have received this transmission in error, please delete the message.  Thank
>you
>
>
>
>--
>To unsubscribe, e-mail:
><ma...@jakarta.apache.org>
>For additional commands, e-mail:
><ma...@jakarta.apache.org>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>

Micael

-------------------------------------------------------

This electronic mail  transmission and any accompanying documents contain 
information belonging to the sender which may be confidential and legally 
privileged.  This information is intended only for the use of the 
individual or entity to whom this electronic mail transmission was sent as 
indicated above. If you are not the intended recipient, any disclosure, 
copying, distribution, or action taken in reliance on the contents of the 
information contained in this transmission is strictly prohibited.  If you 
have received this transmission in error, please delete the message.  Thank you 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Response.ContentType - not always setting contentType in Header

Posted by neal <ne...@yahoo.com>.
Definitive classes.  And I have (and still am) going through the XSLT and
the page classses (the classes that the control servlet calls specific to
the requested page) with a fine tooth comb.  The only thing that the 3
problem pages seem to have in common that I have not yet eliminated is that
they (a) read from the request header info, and (b) do a couple of redirects
if needed based upon that request header info.  But those conditions should
not be applicable to a simple request and thus should not affect the output.
In fact, the status code is 200 (not 302 in the case of a redirect).  So
then, I guess the only really difference that I'm seeing so far is that they
read from the request header.  but I can't imagine that this would make a
difference.  :(

Thanks.
Neal

-----Original Message-----
From: micael [mailto:caraunltd@harbornet.com]
Sent: Tuesday, November 26, 2002 11:27 AM
To: Tomcat Users List
Subject: Re: Response.ContentType - not always setting contentType in
Header


Is it seemingly random or is it definitive classes Neal?

At 11:17 AM 11/26/2002 -0800, you wrote:
>Does anyone know of a reason why response.setContentType() would only
>sometimes set my content type?
>
>I have a single control servlet which sets content type explicitly
>
>response.setContentType("text/html");
>
>just before it opens an outputStream and writes an XSLT transformation to
>out.  For 70% of my pages the contentType is correct.  For 30% of them
(even
>the pages otherwise work perfectly fine) the header info is messed up.
There
>is no contentType specified and contentLenght is 0.  Very strange. In these
>pages (their control classes I do not do anything specific to the response
>object that is any different from the other pages.  In the XsLTs I specify
>output as HTML on all the pages.  Very confusing.
>
>Any thoughts as to why this might happen or how to correct it?  I think it
>may be causing me search engine indexing problems.
>
>Thanks.
>Neal
>
>--
>To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
>For additional commands, e-mail:
<ma...@jakarta.apache.org>

Micael

-------------------------------------------------------

This electronic mail  transmission and any accompanying documents contain
information belonging to the sender which may be confidential and legally
privileged.  This information is intended only for the use of the
individual or entity to whom this electronic mail transmission was sent as
indicated above. If you are not the intended recipient, any disclosure,
copying, distribution, or action taken in reliance on the contents of the
information contained in this transmission is strictly prohibited.  If you
have received this transmission in error, please delete the message.  Thank
you



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Response.ContentType - not always setting contentType in Header

Posted by micael <ca...@harbornet.com>.
Is it seemingly random or is it definitive classes Neal?

At 11:17 AM 11/26/2002 -0800, you wrote:
>Does anyone know of a reason why response.setContentType() would only
>sometimes set my content type?
>
>I have a single control servlet which sets content type explicitly
>
>response.setContentType("text/html");
>
>just before it opens an outputStream and writes an XSLT transformation to
>out.  For 70% of my pages the contentType is correct.  For 30% of them (even
>the pages otherwise work perfectly fine) the header info is messed up. There
>is no contentType specified and contentLenght is 0.  Very strange. In these
>pages (their control classes I do not do anything specific to the response
>object that is any different from the other pages.  In the XsLTs I specify
>output as HTML on all the pages.  Very confusing.
>
>Any thoughts as to why this might happen or how to correct it?  I think it
>may be causing me search engine indexing problems.
>
>Thanks.
>Neal
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>

Micael

-------------------------------------------------------

This electronic mail  transmission and any accompanying documents contain 
information belonging to the sender which may be confidential and legally 
privileged.  This information is intended only for the use of the 
individual or entity to whom this electronic mail transmission was sent as 
indicated above. If you are not the intended recipient, any disclosure, 
copying, distribution, or action taken in reliance on the contents of the 
information contained in this transmission is strictly prohibited.  If you 
have received this transmission in error, please delete the message.  Thank you 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Response.ContentType - not always setting contentType in Header

Posted by neal <ne...@yahoo.com>.
Yes you are correct I believe - you must set the contentType prior to
writing to out.  But ... I am.  And, still 2 of my more important pages are
not showing the contentType as being defined...those same two pages show a
contentLength of 0, and yet those same two pages seem to work perfectly
fine.  

Well, the real reason I am worried about this is that I heard a rumor that
this could affect search engine crawling - that is may prevent some engines
from crawling the content. Does anyone know if this is true?

Thanks.
Neal

-----Original Message-----
From: David Tildesley [mailto:datil@paradise.net.nz]
Sent: Wednesday, November 27, 2002 12:20 AM
To: Tomcat Users List
Subject: RE: Response.ContentType - not always setting contentType in
Header


I think you cannot set contenttype after putting out any response body - so
double check that you set the content type as the very first thing before
sending any response body. HTH

-----Original Message-----
From: neal [mailto:nealcabage@yahoo.com]
Sent: Wednesday, 27 November 2002 8:18 a.m.
To: Tomcat Users List
Subject: Response.ContentType - not always setting contentType in Header


Does anyone know of a reason why response.setContentType() would only
sometimes set my content type?

I have a single control servlet which sets content type explicitly

response.setContentType("text/html");

just before it opens an outputStream and writes an XSLT transformation to
out.  For 70% of my pages the contentType is correct.  For 30% of them (even
the pages otherwise work perfectly fine) the header info is messed up. There
is no contentType specified and contentLenght is 0.  Very strange. In these
pages (their control classes I do not do anything specific to the response
object that is any different from the other pages.  In the XsLTs I specify
output as HTML on all the pages.  Very confusing.

Any thoughts as to why this might happen or how to correct it?  I think it
may be causing me search engine indexing problems.

Thanks.
Neal 



RE: Response.ContentType - not always setting contentType in Header

Posted by David Tildesley <da...@paradise.net.nz>.
I think you cannot set contenttype after putting out any response body - so
double check that you set the content type as the very first thing before
sending any response body. HTH

-----Original Message-----
From: neal [mailto:nealcabage@yahoo.com]
Sent: Wednesday, 27 November 2002 8:18 a.m.
To: Tomcat Users List
Subject: Response.ContentType - not always setting contentType in Header


Does anyone know of a reason why response.setContentType() would only
sometimes set my content type?

I have a single control servlet which sets content type explicitly

response.setContentType("text/html");

just before it opens an outputStream and writes an XSLT transformation to
out.  For 70% of my pages the contentType is correct.  For 30% of them (even
the pages otherwise work perfectly fine) the header info is messed up. There
is no contentType specified and contentLenght is 0.  Very strange. In these
pages (their control classes I do not do anything specific to the response
object that is any different from the other pages.  In the XsLTs I specify
output as HTML on all the pages.  Very confusing.

Any thoughts as to why this might happen or how to correct it?  I think it
may be causing me search engine indexing problems.

Thanks.
Neal