我这样做了:
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, "/*");
}
}
但是还是得到这个:
对于经过验证的表单,情况甚至更糟:
答案 0 :(得分:0)
您可以在Google中找到许多解决此问题的方法(主要是通过添加StringHttpMessageConverter或CharacterEncodingFilter)。但是我尝试的一切都没有帮助。但是我找到了解决方案—为ViewResolver设置字符编码!
resolver.setCharacterEncoding("UTF-8");