3

I am trying to add Internationalization and Localization support to our Spring MVC application. I made encoding like this in *-servlet.xml

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

But I found wrong character like below

enter image description here

I cannot figure out what problem I should fix it. If possible, please let me know.


I've already added in jsp page like this: <%@ page contentType="text/html;charset=UTF-8" language="java" %>

But it doesn't work.

1
  • Please show your controller. Commented Oct 21, 2013 at 19:51

2 Answers 2

2

The defaultEncoding property of ReloadableResourceBundleMessageSource is used to

Set the default charset to use for parsing properties files. Used if no file-specific charset is specified for a file.

It has no bearing on how the client is reading the response. If you are generating your response with a jsp, you can give it this line at the start

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

so that the client knows that you are providing data encoded with the UTF-8 charset.

If you are not using a jsp, there are other ways to set the content-type or content-encoding, directly from HttpServletResponse or from a returned ResponseEntity object.

Sign up to request clarification or add additional context in comments.

1 Comment

beat me for a second. I would like to add, that you should be sure that your properties files are on UTF-8
0

update your default encoding with:

<property name="defaultEncoding" value="ISO-8859-1" />

and this should work for rendering characters with accents. At least it works on my spring projects (french and european languages/users)

If this is not an option for you (bigger audience of targetted users) try to add this in your jsp:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    ...
</head>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.