Skip to main content
Kinetic Community

Change the default encoding for GET parameters

Web servers don't always apply the character encoding defined in the request to GET parameters.  Apache Tomcat will use ISO-8859-1 as the default character encoding of the entire URL, including the query string (GET parameters).  This can result in parameters being improperly decoded if they contain any characters outside of the ISO-8859-1 character set.

Usage

The method to change the character encoding for GET parameters will be different for each web server, so you will need to consult your web server docs.  

For Apache Tomcat specifically, the solution is very easy.  There are two different settings that can be applied to Tomcat to force it to change the character encoding used to decode GET parameters.  They both involve modifying the <Connector> element in the Tomcat server.xml file.

  1. To force all request parameters to use a specific character encoding such as UTF-8, add the URIEncoding attribute to the <Connector> element in the Tomcat server.xml file and set it to the desired value (e.g. URIEncoding="UTF-8").
  2. To force Tomcat to use the character encoding defined in the request, add the useBodyEncodingForURI attribute to the <Connector> element in the Tomcat server.xml file and set it to true (e.g. useBodyEncodingForURI="true").

Example

Here is an example of how the server decodes the following GET parameter before and after adding the encoding attribute to the <Connector> element.

  • GET parameter:  é (French lower case e acute)
  • Before setting the encoding attribute, decoded as: Ã©
  • After setting the encoding attribute to UTF-8, decoded as: é