Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
652 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...