Unable to set request character encoding to UTF-8

While developing my current application I’ve been seeing dozens of error messages like this:

WARNING: PWC4011: Unable to set request character encoding to UTF-8 from context /foo, because request parameters have already been read, or ServletRequest.getReader() has already been called and after searching high and low for a solution I eventually found one.

This problem is being caused by request parameters being encoded differently to the URI. The solution is to put this line:

<parameter-encoding default-charset="UTF-8"/>

at the top of the glassfish-web.xml file (just after the glassfish-web-app element). It will set the default character encoding for parameters to UTF-8 from the default of ISO-8859-1. More information can be found here.