I try to open a webview in java and show the spotify login page. (https://accounts.spotify.com/en/login):
JFrame f = new JFrame();
f.setTitle("Spotify");
f.setSize(500,500);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JFXPanel jfxPanel = new JFXPanel();
f.add(jfxPanel);
Platform.runLater(() -> {
WebView webView = new WebView();
jfxPanel.setScene(new Scene(webView));
WebEngine webEngine = webView.getEngine();
webEngine.load("https://accounts.spotify.com/en/login");
});
The result is the window below. (when i copy the cryptic text and paste it in another application, it shows me the text with right encoding.
How can I display the spotify login page with correct encoding?
You need to check that the encoding of the files on your project mathches with the one from the spotify server response, I already checked the spotify url you gave and is
Content-Type:text/html; charset=utf-8
so, if your file is not utf8, convert it, you can do it with notepad++, on the Encoding menu.I saw this at the dropbox login page in my WebView, too.
The problem you encountered has nothing to do with encoding. The JavaFx WebView has some problems with loading local fonts. If you load a website which wants to load a local font installed on your computer you will see this cryptic letters. If you remove the font you will see the text as usual.
So your problem isn't the encoding of the website, it's the font spotify want's to load and you are having local on your pc.
You will have to find a way to stop the WebView from loading local fonts. Maybe by injecting some code.