Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
...