Java String Encoding for UTF-8

I have HTML code that I store in a Java.lang.String variable. I write this variable to a file and set the encoding to UTF-8 when writing the contents of the string variable to a file in the file system. I open this file and everything looks great, for example. → displayed as a right arrow.

However, if the same line (containing the same content) is used by the jsp page to display content in the browser, characters like → are displayed as a question mark (?)

When storing the contents in a String variable, I'm sure I use:

String myStr = new String(bytes[], charset)  

instead of just:

String myStr = "<html><head/><body>&rarr;</body></html>";

Can someone please tell me why the contents of String are written perfectly to the file system but not displayed in jsp / browser?

Thanks.

+3
3

jsp/browser?

. JSP ,

<%@ page pageEncoding="UTF-8" %>

, HTML <head>:

<meta http-equiv="content-type" content="text/html; charset=utf-8">
+4

:

  • UTF-8
  • Content-Type: text/html; charset=utf-8 HTTP-.
+1
0

Source: https://habr.com/ru/post/1723047/


All Articles