【问题标题】:Problem with Encoding ????? instead letters编码问题??????而不是字母
【发布时间】:2020-06-25 19:51:38
【问题描述】:

使用:Spring mvc、tomcat、thymeleaf 和 instagram4j。当我想显示来自 instagram 的一些信息时,我使用 instagram4j 并从 instagram4j 对象中检索信息,但在页面上我只有 ?????但在想法控制台中,我有很好的信息。 例子 在控制台中: 页面上: 任何带有编码的行为都没有好的结果 感谢帮助

【问题讨论】:

  • 您的项目和应用程序中的文件是否配置为使用 UTF-8?
  • @JorgeCampos 是的,所有项目和应用都配置为使用 UTF-8
  • 我看到是西里尔字母,拉丁字母显示不错。
  • 当我尝试在控制台输出类似 new String(cyrillic.getBytes("Cp1252"), "Cp1251");new String(cyrillic.getBytes("Cp1251"), "UTF-8"); 的操作时,与页面上的输出相同 '??????'

标签: java spring-mvc tomcat gradle


【解决方案1】:

这个答案帮助solution of this problem 在 mvc config ViewResolver 中添加resolver.setCharacterEncoding("UTF-8");

        @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
        resolver.setTemplateEngine(templateEngine());
        resolver.setCharacterEncoding("UTF-8");
        registry.viewResolver(resolver);
    }

【讨论】:

    猜你喜欢
    • 2011-10-16
    • 2010-11-30
    • 2012-03-03
    • 2012-10-10
    • 2020-12-24
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    • 2016-10-20
    相关资源
    最近更新 更多