GWT: Character encoding umlauts

后端 未结 5 1088
后悔当初
后悔当初 2021-01-12 04:24

I want to set a text in a label:

labelDemnaechst.setText(\" Demnächst fällig:\");

On the output in the application the characters \"ä\" are

相关标签:
5条回答
  • 2021-01-12 05:08

    To get UTF-8 encoding for your entire workspace, go to Window -> Preferences. In the pop-up start typing encoding. Now you should have Content Types, Workspace, CSS Files, HTML Files, XML Files as result. In content Types you can type UTF-8 in the Default encoding text box, for the other elements you can just select the encoding in their respective listboxes.

    Then check the encoding for your project in Project -> Properties -> Resource.

    Detailed instruction with pictures can be found here:

    http://stijndewitt.wordpress.com/2010/05/05/unicode-utf-8-in-eclipse-java/

    Cheers

    0 讨论(0)
  • 2021-01-12 05:09

    what i did: open the file with notepad (Windows Explorer), and save it with the option UFT-8 instead of proposed ANSI.

    Encoding the project to UTF-8 didn't work (for me)

    Cheerio

    0 讨论(0)
  • 2021-01-12 05:09

    Use iso-8859-1 (western europe) character set instead of UTF-8.

    0 讨论(0)
  • 2021-01-12 05:12

    well you have to encode your special charactars to Unicode. You can finde a list of the representive Unicode characters here.

    Your examle would look like this:

        labelDemnaechst.setText("Demn\u00E4lachst f\u00E4llig:");
    

    Hope this helps, if noone has a better solution.

    Appendix:

    Thanks Thomas for your tipp, you really have to change the format in which eclipse safes it's source files. Per default it uses something like Cp1252. If you change it to UTF-8, your example works correct. (So Demnächst is written correctly).

    You can edit the safing format, if you right-click on your file --> Preferences. enter image description here

    0 讨论(0)
  • 2021-01-12 05:14

    GWT assumes all source files are encoded in UTF-8 (and this is why you see löschen if you open them with an editor that interprets them as Windows-1252 or ISO-8859-1).

    GWT also generates UTF-8-encoded files, so your web server should serve them as UTF-8 (or don't specify an encoding at all, to let browsers "sniff" it) and your HTML host page should be served in UTF-8 too (best is to put a <meta charset=utf-8> at the beginning of your <head>).

    If a \u00E4 in Java is displayed correctly in the browser, then you're probably in the first case, where your source files are not encoded in UTF-8.

    See http://code.google.com/webtoolkit/doc/latest/FAQ_Troubleshooting.html#International_characters_don't_display_correctly

    0 讨论(0)
提交回复
热议问题