Reputation: 397
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
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.
Upvotes: 3
Views: 356
Reputation: 4040
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>
Upvotes: 0
Reputation: 279940
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.
Upvotes: 2