I have a web app use Spring MVC, version 4.3.8.RELEASE. It save Unicode character incorrect:
I have checked many view points:
(1) In MySQL database, it is NVARCHAR, not VARCHAR
(2)In pom.xml
, I add
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
(3) In JSP page, I add
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
(4) Inside web.xml
, I add
<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>
(5) At bean control message, I add
<beans:bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<beans:property name="basename" value="META-INF/messages/messages"/>
<beans:property name="defaultEncoding" value="UTF-8"/>
</beans:bean>
(6) At ViewResolver, I also add property for UTF-8 ...
But not success. How to fix it?
This is my project: https://github.com/donhuvy/temp_unicode
The question marks tell me (in this case) that the data was mangled as it was inserted into the table. That is, the Vietnamese characters are lost.
Now, to figure out what to do instead. Go to Trouble with utf8 characters; what I see is not what I stored
SELECT HEX(...)...
; Điện lạnh
, when correctly stored (into utf8 or utf8mb4) would be C490 69 E1BB87 6E 20 6C E1BAA1 6E 68
. In your comment Ä?iá»?n lạnh
-- was that after fetching from the table? If so, it is too late.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.