Not getting spanish characters (ú, í )but getting like (ó , Ã) on UI

11,264

Solution 1

and set the properties file with UTF-8 format

There's your mistake.

They are read as ISO-8859-1 and they should therefore be saved as ISO-8859-1. If you intend to present characters which are not available by the ISO-8859-1 character set, then you have basically 3 options:

  1. Use native2ascii tool to convert an UTF-8 saved properties file to an ISO-8859-1 encoded properties file with unicode escapes in form of \uXXXX over all place instead of those "special characters" which are not covered by ISO-8859-1 charset.

  2. Use an properties file editor which is capable of doing #1 automagically, such as the one built in Eclipse. In other words, just create and edit the properties file in Eclipse. It'll worry automagically about the encoding.

  3. Use a custom ResourceBundle.Control implementation wherein you explicitly read the properties file yourself using new InputStreamReader(inputStream, "UTF-8"). However, as non-Spring-user I have no clue how to tell Spring to use that custom Control. In JSF it's easy.

See also:

Solution 2

If your property file looks like this Descripción de artículos but you are getting this on the front-end Descripción de artículos, then the problem is the encoding used to read your property file, here is how you can tell Spring to always use UTF-8:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

@Configuration
public class MessageConfiguration {

    @Bean
    public ReloadableResourceBundleMessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setDefaultEncoding("UTF-8");
        // other config options go here if needed, e.g. path to the property bundle
        return messageSource;
    }
}
Share:
11,264
Admin
Author by

Admin

Updated on August 16, 2022

Comments

  • Admin
    Admin over 1 year

    I declared three locale conversions in three properties files like Strings.properties, Strings_es_ES.properties and Strings_en_GB.properties ( for US, ES and UK)

    In Strings_es_ES.properties,i declared the strings like below and set the properties file with UTF-8 format.

    admin.main.numberofrewards=Número de recompensas:
    admin.main.categorylist=lista Categoría
    

    I am using the above resource bundle in .jsp files like below

    <%@ page pageEncoding="UTF-8"%>
    <h2><spring:message code="admin.main.numberofrewards"/></h2>
    <p><spring:message code="admin.main.categorylist"/></p>
    

    I am getting output on the browser like below

    Nómero de recompensas
    lista CategorÃa
    

    Please help me on this