I'm looking for functional way to set default character encoding for HTTP responses for Geronimo 3 with Tomcat. It seems there is a lot of work-arounds, but not any way to easily set some property in some file like in case of Apache Httpd. (Apache Httpd has AddDefaultCharset
used for all responses.) I've tried add attributes useBodyEncodingForURI
and URIEncoding
to <connector>
elements in var/catalina/server.xml
.
<Connector name="TomcatWebConnector"
port="${HTTPPort + PortOffset}"
address="${ServerHostname}"
protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="${HTTPSPort + PortOffset}"
useBodyEncodingForURI="true"
URIEncoding="UTF-8"
executor="DefaultThreadPool"/>
But it does not work. I still get header Content-Type text/html;charset=ISO-8859-1
in response. Another solution is to programaticaly change headers in application (e.g. via filter or valve), but I don't find it systemic.
I returned to my question I had asked two months ago. I know now that the solution using a filter is not any workaround, but common way. Just write a filter class:
And assign the filter with all URIs in the
WEB-INF/web.xml
file:That's all.