I am facing a challenge with the encoding in my SLD file in GeoServer on a Ubuntu server. When I create a SLD file containing the danish letters æ, ø, å in the GeoServer web interface like this filter:


In the "Style Editor" the "ø" looks fine and when submit I can see (in Firebug) that the posted request contains the letter "ø". But when I try to edit the style again, my filter looks like this:


The "ø" has been replaced with a "?". My SLD header looks like this:

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

I have tried to use Latin-1 encoding

<?xml version="1.0" encoding="ISO-8859-1"?>

But I the "ø" still shows as a "?". When I run env | grep LANG in the terminal on the Ubuntu server I get this output:


This should indicate the default encoding is utf-8. When I run a file --mime-encoding myld.sld I get:


My question is:

How do I get GeoServer to write the sld file in utf-8 encoding or in Latin-1 so I can use the danish letters in my SLDs?

  • Can you try two things? 1. Look at the encoding of the web page in your browser when you're editing the sld. 2. Opens the mysld.sld file in an editor, do you see the danish characters? – unicoletti Mar 9 '12 at 18:45
  • My browsers encoding is "Unicode (UTF-8)". When I open mysld.sld in gedit on the Ubuntu server, I can't see the danish characters as they are replaced with "?" And the Character Set in GeoServer under Global settings also says UTF-8. What am I missing? – taudorf Mar 12 '12 at 8:28
  • can you try updating the SLD through Curl to see if you get the same behavior? docs.geoserver.org/stable/en/user/restconfig/… docs.geoserver.org/stable/en/user/restconfig/… – Ragi Yaser Burhum Mar 12 '12 at 15:25
  • When I upload the SLD through Curl the danish characters looks fine and the "file --mime-encoding myld.sld" returns utf-8. But is there a way to write the sld file with utf-8 encoding using the GeoServer Web Interface and not Curl? – taudorf Mar 13 '12 at 12:07

If files created by Geoserver are in us-ascii, it means that the Java VM is running using this encoding. In your Geoserver starting script, add the Java option (JAVA_OPTS) -Dfile.encoding=UTF-8


I got this error (Invalid byte 2 of 2-byte UTF-8 sequence) when validating the SLD in GeoServer 2.1.3, where the Danish charater Å was used as a ogc:Literal. Editing the SLD file in a text editor kind of fixed the problem. The SLD editor in Geoserver now writes Å as Ã…. But my styling is working.

  • 1
    As I wrote, in my comment above, uploading the SLD through Curl (using the RESTful Configuration) worked for me. The danish charaters look fine both in the SLD editor and when doing a GetLegendGraphic request. But when I create a new SLD with the GeoServer interface I am back to my initial problem. For now I just create a new SLD with the option "Copy from existing style" and choose the SLD uploaded through Curl. But I would still like to know how to write the sld file with utf-8 encoding using the GeoServer Web Interface and not Curl? – taudorf Apr 4 '12 at 6:54

You might want to ask on the Geoserver mailingist for this. I've used Norwegian characters in Geoserver on a ubuntu machine, and never encountered trouble.

The "Invalid byte 2 of 2-byte UTF-8 sequence" error may be related to some byte-order-mark error, but i am not sure. I guess the Geoserver devs haven't tested all kinds of "strange" characters, so chances are they've never tested for these things. A post on the mailinglist describing your problem could lead to a solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.