This question has already been answered:

Hello, I need help with utf-8 encoding. I am working on a Spring MVC project. I connected a bin:

 <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="defaultEncoding" value="UTF-8"/> <property name="basenames" value="classpath:messages,classpath:ValidationMessages"/> </bean> 

Also files for localization

 messages_ru.properties, 

files for localization of validation

 ValidationMessages.properties 

on the jsp page I use:

 <spring:message code="firstname"/> <form:errors path="firstname" cssClass="error"></form:errors> 

and everything works fine, but there is one problem - all that is in ValidationMessages.properties in Russian - I get on jsp :

BRIDE BRIDE BRAND BRACKET

and с messages_ru.properties everything is well displayed in Russian.

It blows up the brain, what's the problem? I "googled" everything I could, also tried to add the "bin" validator and do a ref to messageSource - messageSource success.

Thanks for attention.

Reported as a duplicate by Sergey Gornostaev java 2 May '18 at 13:52 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • At jsp-page attribute pageEncoding specified? - Sergey Gornostaev
  • encoding-filter org.springframework.web.filter.CharacterEncodingFilter - alex uio
  • one
    Try inserting <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> at the beginning of the jsp file. - Sergey Gornostaev

3 answers 3

  1. Directly in the browser, change the encoding to utf-8 (in chrome settings icon / additional tools / encoding). If it helps, add the page to the <head><meta charset="UTF-8"></head> .

  2. Check the ValidationMessages.properties file itself, in which encoding it is saved, and forcibly save it in utf-8.

    This may be a problem with the default encoding of the cat depends on the OS,
    try to check from the application which encoding is installed by default

      System.out.println(Charset.defaultCharset()); 

    if it is not UTF-8, then add startup parameters for jvm

      -Dfile.encoding=UTF8 

      Try another filter in the web-xml: <filter> <filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>