UTF-8 (Hindi) text does not appear in browser window or Eclipse console

I need to display text in Hindi (or any regional language) on browser screens. I get this text from the database.

To do 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 can get the hindi text perfectly in the hindiText variable. But when I print it on the eclipse console or on the browser screen, I get only ???? ?? ?? ???? ?? ??

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

Can someone help me solve this problem? What setting am I missing?

Just fyi - I can open Hindi sites in my browser. Therefore, language settings are not a problem.

EDIT

Since I use JSP files for my presentations, I added the following to my web.xml to set character encoding all over the world. Link: Follow-up

 <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!

+1
source share
3 answers

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

As for the Eclipse part, you need to tell it to use UTF-8 for your stdout console. You can set this using window> Settings> General> Workspace> Text File Encoding.

enter image description here

As for the JSP part, you need to tell it to use UTF-8 to record the HTTP response body. You can set this with

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

in each individual JSP or application nationwide

 <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:

+7
source

use your code this way

 System.out.println("\u0905\u092d\u0940\u0938\u092e\u092f\u0939\u0948\u091c"); 
0
source

The problem is that the output streams you use are likely to have the "standard" encoding of your platform. On Windows, this is often a crappy MS 8-bit code page.

Make it a habit to print text with PrintWriters and make sure they are created with the correct encoding.

0
source

Source: https://habr.com/ru/post/949807/


All Articles