Discussion:
Default Charset in Content-Type Header
Alpay Ozturk
2005-09-22 09:37:09 UTC
Permalink
Hi,

I am using Tomcat 4.1.29 in a production environment and I want tomcat
not to add default charset in Content-Type response header.
Is it possible?

Thanks in advance.

Alpay
Jilles van Gurp
2005-09-22 11:08:55 UTC
Permalink
Post by Alpay Ozturk
Hi,
I am using Tomcat 4.1.29 in a production environment and I want tomcat
not to add default charset in Content-Type response header.
Is it possible?
Thanks in advance.
Alpay
---------------------------------------------------------------------
No, it's not possible for text/* types. Tomcat will set a default
charset if you don't set it yourself. For jsps you can change the
default encoding by overriding it in your web.xml (see conf/web.xml for
the defaults).

BTW I suspect you might be wanting this because you are trying to set
the content type twice: first to text/html (tomcat will set a charset
automatically because the servlet spec says text/html should be
accompanied by a charset) and then to application/pdf (you end up with
content-type: application-pdf; charset=utf-8). We ran into this issue
before: you can't get rid of the charset once it is set and you need to
set a content-type before you start streaming content.

The only thing you might be able to do is to filter the http header with
apache or something. Trying to correct this from a servlet filter is
tricky because the headers are streamed to the client before the
content. The only way to work around this is to wrap the response and
buffer the output, set the header in the real response and the stream
the buffered content (tomcat will still set a default charset if the
type is text/*).

The best solution is to simply accept that the charset needs to be set
correctly for text/* and to do that yourself.

Jilles
James Annesley
2005-09-22 11:18:18 UTC
Permalink
I want to configure TomCat 4.1.30 to allow Remote Deployment of my mobile
app. This article
http://developers.sun.com/techtopics/mobility/midp/articles/deploy/ tells
one how to do it for system wide settings. I want to configure it on a per
application basis. How do I do this? Is it possible? What is the correct
format for the .war file and web.xml entries? Bare in mind that I am not
talking about a servlet here.

Thanks

James
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.4/109 - Release Date: 21/09/2005
Alpay Ozturk
2005-09-22 11:42:06 UTC
Permalink
Thanks Jilles ,

I need to set the content-type of a servlet response as
"application/vnd.wap.mms-message". But I will recheck my code if I am
setting content-type to text/html before setting it to
"application/vnd.wap.mms-message". If it does not work, I will wrap the
response as you suggested. Thanks for your response and suggestions.

Regards,

Alpay
Post by Jilles van Gurp
Post by Alpay Ozturk
Hi,
I am using Tomcat 4.1.29 in a production environment and I want tomcat
not to add default charset in Content-Type response header.
Is it possible?
Thanks in advance.
Alpay
---------------------------------------------------------------------
No, it's not possible for text/* types. Tomcat will set a default
charset if you don't set it yourself. For jsps you can change the
default encoding by overriding it in your web.xml (see conf/web.xml for
the defaults).
BTW I suspect you might be wanting this because you are trying to set
the content type twice: first to text/html (tomcat will set a charset
automatically because the servlet spec says text/html should be
accompanied by a charset) and then to application/pdf (you end up with
content-type: application-pdf; charset=utf-8). We ran into this issue
before: you can't get rid of the charset once it is set and you need to
set a content-type before you start streaming content.
The only thing you might be able to do is to filter the http header with
apache or something. Trying to correct this from a servlet filter is
tricky because the headers are streamed to the client before the
content. The only way to work around this is to wrap the response and
buffer the output, set the header in the real response and the stream
the buffered content (tomcat will still set a default charset if the
type is text/*).
The best solution is to simply accept that the charset needs to be set
correctly for text/* and to do that yourself.
Jilles
---------------------------------------------------------------------
KEREM ERKAN
2005-09-22 10:51:07 UTC
Permalink
You may add the charset of your choice (probably Turkish) to your jsp by
adding

<%@ page contentType="text/html; charset=iso-8859-9" %>

To the beginning of your jsp page. If you do not add this, Tomcat will
always default to ISO-8859-1 or UTF-8 (I don't remember which one was
default).

Regards,

Kerem
-----Original Message-----
Sent: Thursday, September 22, 2005 12:37 PM
To: Tomcat Users List
Subject: Default Charset in Content-Type Header
Hi,
I am using Tomcat 4.1.29 in a production environment and I
want tomcat
not to add default charset in Content-Type response header.
Is it possible?
Thanks in advance.
Alpay
Alpay Ozturk
2005-09-22 11:38:07 UTC
Permalink
Thanks Kerem ,

But I need to set the content-type of a servlet response as
"application/vnd.wap.mms-message" without adding a charset header. Since
some handsets do not accept the MMS response messages although the
messsage is well-encoded. Anyway, thanks for your response.

Regards,

Alpay
Post by KEREM ERKAN
You may add the charset of your choice (probably Turkish) to your jsp by
adding
To the beginning of your jsp page. If you do not add this, Tomcat will
always default to ISO-8859-1 or UTF-8 (I don't remember which one was
default).
Regards,
Kerem
-----Original Message-----
Sent: Thursday, September 22, 2005 12:37 PM
To: Tomcat Users List
Subject: Default Charset in Content-Type Header
Hi,
I am using Tomcat 4.1.29 in a production environment and I
want tomcat
not to add default charset in Content-Type response header.
Is it possible?
Thanks in advance.
Alpay
Jon Wingfield
2005-09-22 12:01:10 UTC
Permalink
Return binary content from a servlet using the ServletOutputStream and
you should have no problem.
This is the way we vend MMS data. (In fact all of our binary data.)

HTH,

Jon
Post by Alpay Ozturk
Thanks Kerem ,
But I need to set the content-type of a servlet response as
"application/vnd.wap.mms-message" without adding a charset header. Since
some handsets do not accept the MMS response messages although the
messsage is well-encoded. Anyway, thanks for your response.
Regards,
Alpay
Post by KEREM ERKAN
You may add the charset of your choice (probably Turkish) to your jsp by
adding
To the beginning of your jsp page. If you do not add this, Tomcat will
always default to ISO-8859-1 or UTF-8 (I don't remember which one was
default).
Regards,
Kerem
-----Original Message-----
Sent: Thursday, September 22, 2005 12:37 PM
To: Tomcat Users List
Subject: Default Charset in Content-Type Header
Hi,
I am using Tomcat 4.1.29 in a production environment and I
want tomcat
not to add default charset in Content-Type response header.
Is it possible?
Thanks in advance.
Alpay
---------------------------------------------------------------------
Loading...