西里尔字母未显示在Spring MVC上

时间:2018-09-08 15:12:34

标签: java spring spring-mvc tomcat java-ee

我这样做了:

public class FilterInit implements WebApplicationInitializer {
    @Override
    public void onStartup(ServletContext servletContext) {
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter("UTF-8");
        characterEncodingFilter.setForceEncoding(true);
        characterEncodingFilter.setForceRequestEncoding(true);
        FilterRegistration.Dynamic endcodingFilter = servletContext.addFilter("endcodingFilter", characterEncodingFilter);
        endcodingFilter.addMappingForUrlPatterns(null, false, "/*");
    }
}

但是还是得到这个:

screenshot

对于经过验证的表单,情况甚至更糟:

screenshot

1 个答案:

答案 0 :(得分:0)

您可以在Google中找到许多解决此问题的方法(主要是通过添加StringHttpMessageConverter或CharacterEncodingFilter)。但是我尝试的一切都没有帮助。但是我找到了解决方案—为ViewResolver设置字符编码!

 resolver.setCharacterEncoding("UTF-8");