Character encoding UTF-8 not working

Asked

Viewed 1,328 times

0

I know that the issue has been commented on numerous times in various blogs and forums around the world, but I really do not know what may be causing, because I think that in setting up my project is all ok:

pages *.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<html>
<head>
    <meta charset="utf-8">
    <title>JooceBox v1.0</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

web xml.

<filter>
    <filter-name>SetCharacterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>SetCharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

I also set as parameter in the connection to the database itself:

<property name="url" value="jdbc:mysql://localhost:3306/viatgedb?useUnicode=yes&amp;characterEncoding=UTF-8"/>

Even with such settings when I will save some record with accents the same stays as follows:

'Joã£o Manuel', 'Heartthrob Bonin''

  • Ever tried to use ISO 8859-1?

  • Hi @Edi.Gomes already tried, but without success

  • 1

    It should work with all this. But make sure your table in the database is like UTF-8 also. If you log the data into the persistence layer, the accents are correct or not. It is very important to isolate the problems before any attempt, that is, whether it occurs in HTTP interpretation or in communication with BD.

1 answer

2


I solved the problem by following this post.

It seems that in modern browsers at the time it is made the submmit of the form by method POST is not sent the HTTP header Accept-Encoding. Hence the standard specification of Servlets specifies the encounter Latin-1/ISO-8859-1.

Simply what needs to be done is to add the filter SetCharacterEncodingFilter in the web xml. as the first in the file.

Already for requisitions of the type GET just edit the tag <connector> filing cabinet xml server. (Apache Tomcat) adding the following attributes: URIEncoding="UTF-8" useBodyEncodingForURI="true"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.