All data on the page is displayed correctly. Text retrieved from the database, including. But when sending the form, the text comes to windows-1252 to the controller.

In jsp encoding specified

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 

Also indicated the encoding for the form itself.

  <form:form method="POST" action="/event" modelAttribute="message" acceptCharset="UTF-8"> 

In the web.xml set filter

 <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> 

What could be the problem?

    1 answer 1

    This problem occurs if the decoder filter is not the first. In my case, spring security was to blame. After transferring the entire configuration from java config to xml and setting the decoder to the spring security filter, the data started coming in the correct encoding.