UTF-8 text (Hindi) not getting displayed on Browser window or Eclipse console

I have to display text in Hindi (or any regional language) on the browser screens. I will be getting this text from the database.

For this I started at a very basic level with the following:

String escapedStr = "\\u0905\\u092d\\u0940 \\u0938\\u092e\\u092f \\u0939\\u0948 \\u091c\\u0928\\u0924\\u093e";
String hindiText = StringEscapeUtils.unescapeJava(escapedStr);
System.out.println(hindiText);
return hindiText;

I am able to get the Hindi text perfectly fine in the variable hindiText. But when I print it on eclipse console or on the browser screen I get only ???? ?? ??

I set the default character encoding of my browser as well as my eclipse console to UNICODE(UTF-8). But still no success.

Can anyone help me solve this? What setting am I missing?

Just fyi - I am able to open hindi websites in my browser. So language settings is not an issue.

EDIT

As I am using JSP files for my views, I have added the following to my web.xml for setting the character encoding globally. Ref: Followed this

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <page-encoding>UTF-8</page-encoding>
    </jsp-property-group>
</jsp-config>

But still no success!


Solution 1:

But when I print it on eclipse console or on the browser screen I get only ???? ?? ??

As to Eclipse part, you need to tell it to use UTF-8 for its stdout console. You can set that by Window > Preferences > General > Workspace > Text File Encoding.

enter image description here

As to the JSP part, you need to tell it to use UTF-8 to write HTTP response body. You can set that by either

<%@page pageEncoding="UTF-8"%>

in every individual JSP, or applicationwide by

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <page-encoding>UTF-8</page-encoding>
    </jsp-property-group>
</jsp-config>

in web.xml.

See also:

  • Unicode - How to get the characters right?