Skip to main content

Ajax partial response encoding issue

2 replies [Last post]
Joined: 2010-01-21

During response rendering ajax request performs rendering by using the encoding from the request. However, the encoding in the partial response document is hardcoded to UTF-8 which leads to problems at least with certain browsers (e.g. IE). Lets assume the request comes in with ISO-8859-1 and thus the response with current code looks like this:

<?xml version="1.0" encoding="utf-8"?>

If I have content with for example scandinavian alphabets (åäö), the response document causes problems in the browser: HTTP headers state that encoding is ISO-8859-1, the XML document states encoding is UTF-8 but the content is encoded with ISO-8859-1. This clearly violates encoding rules. I made a little change to PartialResponseWriter which seem to work pretty nicely and fixes this problem.

Current code:

public void startDocument() throws IOException {
ResponseWriter writer = getWrapped();
writer.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
writer.startElement("partial-response", null);

And the new code looks like this:

public void startDocument() throws IOException {
ResponseWriter writer = getWrapped();
// PACI 20.1.2010 {
String encoding = writer.getCharacterEncoding( );
if( encoding == null )
encoding = "utf-8";
writer.write("<?xml version='1.0' encoding='" + encoding + "'?>\n");
// } PACI 20.1.2010
writer.startElement("partial-response", null);



Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-06

I agree with your assessment, and I've filed a bug to track putting the fix in:



P.S. I could have sworn that UTF-8 was required by the spec, but... turns out it's not.

Jim Driscoll

I've applied your suggested fix to the codebase, I expect it should show
up in tonight's nightly.

Thanks for the suggestion!


To unsubscribe, e-mail:
For additional commands, e-mail: