Unicode字符(阿拉伯字母)在IDE控制台中显示为问号 [英] Unicode characters (Arabic letters) show up as question marks in IDE console
问题描述
我使用JSF 2.0,我有文本字段
< h:form&
< h:inputText value =#{myBean.myValue}/>
< h:commandButton value =Submitaction =#{myBean.printMe()}/>
< / h:form>
public void printMe(){
System.out.println(first line ==+ myValue +==);
System.out.println(second line ==يشسيبشسيبشسيبشيس==);
}
当我运行这个项目并输入يشسيبشسيبشسيبشيس
在文本框中,在IDE控制台中,如下所示。
INFO:first line == ???? ==
INFO:second line == ==
有什么想法为什么会发生这种情况?
解决方案这是使用错误的控制台编码造成的。
System.out.println(My Data is+ fullName);
打印到标准输出(stdout)。您需要将其配置为使用UTF-8。假设您使用的是Eclipse,那么您需要通过
首选项>常规>工作区>文本文件编码,将stdout编码更改为UTF-8。
>
如果你使用Netbeans,我不能从顶部回答,回到这个答案:希伯来语在netbeans中显示为问号,其中包含指向此 Netbeans Wiki < a>其中提到以下内容:
要更改项目的语言编码:
- 在Projects(项目)窗口中右键单击项目节点,然后选择Properties(属性)。
- 在Sources下,从Encoding下拉字段中选择一个编码值。
另请参阅:
>具体问题,过滤器中的那些行是不必要的
res.setCharacterEncoding(UTF-8);
res.setContentType(text / html; charset = utf-8);
它们在JSF2 / Facelets的情况下默认为正确的值。删除这些行。
I am using JSF 2.0 and I have text field as
<h:form>
<h:inputText value="#{myBean.myValue}" />
<h:commandButton value="Submit" action="#{myBean.printMe()}" />
</h:form>
public void printMe() {
System.out.println("first line==" + myValue + "==");
System.out.println("second line==يشسيبشسيبشسيبشيس==");
}
When I run this project and enter يشسيبشسيبشسيبشيس
in textbox, in IDE console I see as below.
INFO: first line==????????????????==
INFO: second line==????????????????==
Any idea why this is happening?
This is caused by using the wrong console encoding.
The line
System.out.println("My Data is " + fullName);
prints to the standard output (stdout). You need to configure it to use UTF-8 as well. Assuming that you're using Eclipse, then you need to change the stdout encoding to UTF-8 by Window > Preferences > General > Workspace > Text File Encoding.
If you're using Netbeans, which I can't answer from top of head, head to this answer: hebrew appears as question marks in netbeans which contains a link to this Netbeans Wiki which mentions the following:
To change the language encoding for a project:
- Right-click a project node in the Projects windows and choose Properties.
- Under Sources, select an encoding value from the Encoding drop-down field.
See also:
Unrelated to the concrete problem, those lines in the filter are unnecessary
res.setCharacterEncoding("UTF-8");
res.setContentType("text/html;charset=utf-8");
They defaults in case of JSF2/Facelets to proper values already. Remove those lines.
这篇关于Unicode字符(阿拉伯字母)在IDE控制台中显示为问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!