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