Anton Ovsyannikov
Anton Ovsyannikov

Reputation: 1200

Java Swing: HTML form in JEditorPane - text input encoding problem

I have a JEditorPane with HTML form and one <input name="rword" type="text"> inside. I'm getting user input by catching FormSubmitEvent with .getData() method.

The mystical thing is that, if I run the app in Netbeans IDE, everything is ok - I get URL encoded input in UTF-8, as expected.

But if I run the jar file from command prompt, getData() returns the user input in ANSI encoding!

I.e. If I type ф in the form, getData will return rword=%D1%84 as expected, but from command line it returns rword=%F4! And I didn't find any method to detect encoding. All my experiments with setting content type with charset=utf-8 have failed. Any ideas?

Upvotes: 2

Views: 221

Answers (1)

Anton Ovsyannikov
Anton Ovsyannikov

Reputation: 1200

The problem is in default charset, so run jvm with file.encoding=UTF-8 option

java -Dfile.encoding=UTF-8 -jar jarfile.jar

Upvotes: 2

Related Questions