UTF-8 文本(印地语)未显示在浏览器窗口或 Eclipse 控制台上 [英] UTF-8 text (Hindi) not getting displayed on Browser window or Eclipse console

查看:14
本文介绍了UTF-8 文本(印地语)未显示在浏览器窗口或 Eclipse 控制台上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在浏览器屏幕上以印地语(或任何区域语言)显示文本.我将从数据库中获取此文本.

为此,我从一个非常基本的层面开始:

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

我能够在变量 hindiText 中完美地获得印地语文本.但是当我在 eclipse 控制台或浏览器屏幕上打印它时,我只得到 ????????

我将浏览器和 Eclipse 控制台的默认字符编码设置为 UNICODE(UTF-8).但仍然没有成功.

谁能帮我解决这个问题?我缺少什么设置?

仅供参考 - 我可以在浏览器中打开印地语网站.所以语言设置不是问题.

编辑

由于我在视图中使用 JSP 文件,因此我已将以下内容添加到我的 web.xml 以全局设置字符编码.参考:

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!

解决方案

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.

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:

这篇关于UTF-8 文本(印地语)未显示在浏览器窗口或 Eclipse 控制台上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆