3

我正在使用 JSF 2.0,我的文本字段为

<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==يشسيبشسيبشسيبشيس==");
}

当我运行这个项目并يشسيبشسيبشسيبشيس在文本框中输入时,在 IDE 控制台中我看到如下。

INFO: first line==????????????????==
INFO: second line==????????????????==

知道为什么会这样吗?

4

2 回答 2

7

这是由于使用了错误的控制台编码造成的。

线

System.out.println("My Data is " + fullName);

打印到标准输出 (stdout)。您还需要将其配置为使用 UTF-8。假设您使用的是 Eclipse,那么您需要通过Window > Preferences > General > Workspace > Text File Encoding将 stdout 编码更改为 UTF-8 。

enter image description here

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:

  1. Right-click a project node in the Projects windows and choose Properties.
  2. 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.

于 2012-11-19T11:20:17.710 回答
-2

如果数据来自数据库,请检查字段数据类型是否为 nvarchar。

于 2012-11-19T10:59:16.483 回答