When sending a POST request from the jsp page to the controller, the data that is entered in Russian or Ukrainian is displayed as a string

I have already reviewed all the solutions to the problem, but nothing helps. Initially I thought it was a problem in the database, but no.

I did everything as it was written on the Internet:

  1. since by using tomkat I have prescribed a URI encoding

    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="UTF-8" /> 
  2. page encoding: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

  3. Meta tag: <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  4. in config class added:

     private static final String VIEW_RESOLVER_CONTENT_TYPE = "text/html;charset=UTF-8"; viewResolver.setContentType(VIEW_RESOLVER_CONTENT_TYPE);` 
  5. Since the configuration is set programmatically, I added web.xml and there I registered the jsp configuration

     <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <page-encoding>UTF-8</page-encoding> </jsp-property-group> </jsp-config> 

    `

But nothing that I did did not help me.

  • request.setCharacterEncoding ("UTF-8"); response.setCharacterEncoding ("UTF-8"); - Aslan Kussein
  • @RequestMapping(value = "/user/register", method = RequestMethod.POST) public String createNewUser( @Valid @ModelAttribute("user") RegistrationForm userAccountData, BindingResult result, WebRequest request) throws DuplicateEmailException { } How to @RequestMapping(value = "/user/register", method = RequestMethod.POST) public String createNewUser( @Valid @ModelAttribute("user") RegistrationForm userAccountData, BindingResult result, WebRequest request) throws DuplicateEmailException { } it in my method? Or is it better to do it in the interceptor? - Andriy Dzigar

1 answer 1

You must specify the encoding on the input:

 request.setCharacterEncoding("UTF-8"); <filter> <filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>