Why do I get Cyrillic from the HTML form comes into the program in the form of gibberish?

0 like 0 dislike
42 views
Hello.
Doing a pet project in the form of a CRUD web application - Anglo-Russian dictionary.
On the back of Java.
At the front clean khtml, formed freemarker.
Used Spring mvc.
Enter in the form of data - text in Russian, check that comes on the controller, and there are all sorts of gibberish.
Here is a screenshot.
5b86ef7ae9ca2956421663.png

That IDEA is displayed during debug. The breakpoint is just on the controller, which intercepts the request.
5b86f0daf2c5b783183013.png

All the pages I have to utf-8. Additionally, it is put in the configuration of the spring:
@Bean getViewResolver public ViewResolver() { FreeMarkerViewResolver freeMarkerViewResolver = new FreeMarkerViewResolver(); freeMarkerViewResolver.maps(1); freeMarkerViewResolver.setPrefix("); freeMarkerViewResolver.setSuffix(".ftl"); freeMarkerViewResolver.setContentType("text/html; charset=UTF-8"); return freeMarkerViewResolver; } @Bean getFreeMarkerConfigurer public FreeMarkerConfigurer() { FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer(); freeMarkerConfigurer.setTemplateLoaderPaths("/", "/WEB-INF/views/"); freeMarkerConfigurer.setDefaultEncoding("UTF-8"); return freeMarkerConfigurer; }


The page where send the data:
<!DOCTYPE html>Add a new wordAdd a new wordWord:

Value:


Back
by | 42 views

1 Answer

0 like 0 dislike
Helped review Moskus . Had to add code to WebAppInitializer. In the end, this class looks like this:
public class WebAppInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(SpringConfig.class, WebConfig.class); context.setServletContext(servletContext); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(context)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); FilterRegistration.Dynamic filterRegistration = servletContext .addFilter("characterEncodingFilter", characterEncodingFilter); filterRegistration.addMappingForUrlPatterns(null, false, "/*"); } }


Added the following piece:
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); FilterRegistration.Dynamic filterRegistration = servletContext .addFilter("characterEncodingFilter", characterEncodingFilter); filterRegistration.addMappingForUrlPatterns(null, false, "/*");
by
110,608 questions
257,187 answers
0 comments
40,796 users