Detect the URI encoding automatically in Tomcat
- by Roland Illig
I have an instance of Apache Tomcat 6.x running, and I want it to interpret the character set of incoming URLs a little more intelligent than the default behavior. In particular, I want to achieve the following mapping:
So%DFe => Soße
So%C3%9Fe => Soße
So%DF%C3%9F => (error)
The bevavior I want could be described as "try to decode the byte stream as UTF-8, and if it doesn't work assume ISO-8859-1".
Simply using the URIEncoding configuration doesn't work in that case. So how can I configure Tomcat to encode the request the way I want?
I might have to write a Filter that takes the request (especially the query string) and re-encodes it into the parameters. Would that be the natural way?