Я просто не могу понять, почему при настройке кодировки utf-8 на сервере wildfly я получаю неправильные символы в контроллере MVC spring. Я отправляю utf-8, получаю utf-8, если просмотр на CharsetDetector, но символы не работают! Помоги пожалуйста! Настройки Wildfly:
<server name="default-server">
<http-listener name="default" socket-binding="http" url-charset="UTF-8" redirect-socket="https" enable-http2="true"/>
<https-listener name="https" socket-binding="https" url-charset="UTF-8" security-realm="ApplicationRealm" enable-http2="true"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<http-invoker security-realm="ApplicationRealm"/>
</host>
<host name="admin.study-lang.ru" alias="admin.study-lang.ru,www.admin.study-lang.ru" default-web-module="learningEnglishWords.war"/>
</server>
<servlet-container name="default" default-encoding="UTF-8" use-listener-encoding="true">
<jsp-config/>
<websockets/>
</servlet-container>
Клиент js jquery:
var obj = {word: word, translation: translation, sentencesStr: sentences.toString(), mnemonic: mnemonic,
transcription: transcription};
var wordsJSON = JSON.stringify(obj);
$.ajax({
type: "POST",
dataType: "HTML",
response:'text',
data: "wordsJSON=" + wordsJSON,
url: "saveWord.htm",
success: function(data) {
var json = JSON.parse(data);
if(json.result == 'true') {
updateDataTable();
alert('Слово обновилось!');
} else if(json.errorMessage != undefined && json.errorMessage != '') {
alert(json.errorMessage);
} else {
alert('Ошибка при сохранении. Обратитесь к администратору!');
}
}
});
Код контроллера:
@RequestMapping(value = "/saveWord.htm", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<String> saveWord(ModelMap model,HttpSession session,HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String wordsJSON = (String) request.getParameter("wordsJSON");
log.info("wordsJSON=" + wordsJSON);
log.info(new String(wordsJSON.getBytes("ISO-8859-1"), "UTF-8"));
CharsetDetector detector = new CharsetDetector();
detector.setText(wordsJSON.getBytes());
log.info("detect=" + detector.detect().getName());
log.info("detectq=" + detector.detect().getString());
Журналы:
wordsJSON={"word":"blue","translation":"トヒᄇ","sentencesStr":"","mnemonic":"トヒᄇ","transcription":"ad"}
{"word":"blue","translation":"??????","sentencesStr":"","mnemonic":"??????","transcription":"ad"}
detect=UTF-8
мои фильтры кодирования:
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>