If the coding of your page is correct, for example when sending the HTTP header:
Content-Type: text/html; charset=utf-8
Or by specifying it in the HTML itself:
<meta charset="utf-8" />
or
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Then at first you do not have to do anything: the String
class already works with Unicode characters (being represented internally by UTF-16 if I'm not mistaken), and the webserver itself must be able (just make sure that the encoding you are declaring is the same encoding as the using ). >
Other encodings other than UTF-8 can be used (Cp1252 / Windows-1252 or ISO-8859-1 / ISO-Latin or some other), but I do not recommend: UTF-8 is very universal, and should be understood by any non-prehistoric browser .
Finally, a comment on URLEncoder
: what it does is to encode a string so that it can be used as a URL. That is not the same as encoding it to be used as content for an HTML page - if you use this method and then include the result on a page, the user will see the "strange" characters. If you need to hardcode your string in ASCII, you need to transform Unicode characters into HTML entities - which is a distinct process, and I do not know how to do it in Java. But at first this should not be necessary - and if it is, it should greatly increase the size of the page generated.