Wrong form coding on Spring MVC

I get form data in my Spring MVC controller, but when I try to enter non-ASCII characters, I get garbage áéíóúconverted to áéíóú.

I use <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>jsp on the pages, Tomcat is configured to receive UTF-8part of the URI / Connection, and form- on acceptCharset="UTF-8". I don’t know where to look further.

I am testing Firefox 38.0 on Ubuntu 14.04. The server is also located on Ubuntu 14.04.

+4
source share
2 answers

You need to add an encoding filter to your web.xml so that it encodes characters correctly:

<filter>
    <filter-name>encoding-filter</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>encoding-filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
+2
source

, UTF-8 latin1, char (, á ( C3 A1) á ( C3 A1)).

HTML, <meta> <head>:

<meta charset="utf-8" /> ( HTML5 DOCTYPE).

+1

Source: https://habr.com/ru/post/1589198/


All Articles