Please tell me how to solve this problem:
Locale locale = new Locale(language);
ResourceBundle messages = ResourceBundle.getBundle("i18n.messages", locale, utf8Control);
try {
String message = new String(messages.getString(key).getBytes("ISO-8859-1"), "UTF-8");
pageContext.getOut().write(message);
} catch (IOException e) {
e.printStackTrace();
}
I'm trying to implement localization, I get the text from the created messages file, the problem is that instead of the necessary characters, it outputs "?????? ??????? ????" Googled, the problem seems to be with encodings, I tried to do it like this:
String message = new String(messages.getString(key).getBytes("ISO-8859-1"), "UTF-8")
And also created utf8Control:
public class Utf8Control extends ResourceBundle.Control {
@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload)
throws IllegalAccessException, InstantiationException, IOException {
String bundleName = toBundleName(baseName, locale);
String resourceName = toResourceName(bundleName, "properties");
ResourceBundle bundle = null;
InputStream stream = null;
if (reload) {
URL url = loader.getResource(resourceName);
if (url != null) {
URLConnection connection = url.openConnection();
if (connection != null) {
connection.setUseCaches(false);
stream = connection.getInputStream();
}
}
} else {
stream = loader.getResourceAsStream(resourceName);
}
if (stream != null) {
try {
bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8"));
} finally {
stream.close();
}
}
return bundle;
}
}
Nothing has happened... JSP has "UTF-8" encoding, files - default "ISO-8859-1"