java - html页面显示问号而不是俄文字母
问题描述
如果有人知道这是怎么回事,请帮忙。我已经尝试了我在互联网上找到的所有内容,但到目前为止无济于事。出于某种原因,在 Idea 中启动项目时,页面上会显示问号而不是俄语字母
我已经尝试过的:
我确保 Windows 控制台以 866 响应 chcp 请求 我读到最好设置此值
同样在区域标准设置的选项卡中,我单击了“更改系统语言”按钮,并取消选中了“测试版:使用 Unicode (UTF-8) 支持全球语言”。保存并重新启动。
在文件idea.exe.vmoptions和idea64.exe.vmoptions添加了以下行: - Dfile.encoding = UTF-8 还在编辑器中添加了Idea> EditConfigurations> Tomcat> VM options。还在编辑器中添加了它Idea> Help> Edit Custom VM Options
同样在File> Settings> FileEncodings设置中将Global Encoding设置为 UTF-8 Project Encoding to UTF-8 Default encoding for project files : UTF-8 Create UTF-8 files with NO BOOM
在编辑器的右下角,我也设置了UTF-8
我以这种格式将元标记放在标题中。
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'/>
我还重新保存了我的 index.html,以防万一使用 UTF-8 编码的记事本
我通过双击文件夹启动了 index.html 页面本身,它通常会显示俄语的按钮,以及俄语的测试文本。但是,当我出于某种原因单击idea中的运行Tomcat按钮时,页面显示问号而不是俄语字母
如此处所述配置tomcat:https ://www.baeldung.com/tomcat-utf-8
然而,由于某种原因,通过idea启动项目时,Content-type显示在responce-headers中:text / html;字符集 = ISO-8859-1
IntellIJ Idea v2020.1 MavenVersion v3.6.1 项目SDK 1.8 Java版 TomCat v9.0.48
依赖项 spring-core 5.2.16.RELEASE spring-context 5.2.16.RELEASE spring-web 5.2.16.RELEASE spring-webmvc 5.2.16.RELEASE thymeleaf-spring5 3.0.12.RELEASE javax.servlet-api 4.0.1
我发现网站页面上的俄语从字母变成问号的时刻。
首先,当我的索引在目录中时一切正常打开 webapp> Index 然后当我创建两个设置类 SpringConfig 实现 WebMvcConfigurer 和 SpringMvcDispatcherServletInitializer 扩展 AbstractAnnotationConfigDispatcherServletInitializer 并将我的索引放在路径下 webapp> WEB-INF> index.html 开始通过调用主控制器。从这一刻起,俄语字母不再被识别。
这是开始出现错误的最小代码。
主控制器
package ru.shop.three_d_print.сontrollers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class MainController
{
@GetMapping
public String index()
{
System.out.println("called");
return "index";
}
}
SpringConfig
package ru.shop.three_d_print.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.thymeleaf.spring5.SpringTemplateEngine;
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;
@Configuration
@ComponentScan("ru.shop.three_d_print")
@EnableWebMvc
public class SpringConfig implements WebMvcConfigurer
{
private final ApplicationContext applicationContext;
@Autowired
public SpringConfig(ApplicationContext applicationContext)
{
this.applicationContext = applicationContext;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry)
{
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
@Override
public void configureViewResolvers(ViewResolverRegistry registry)
{
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
resolver.setTemplateEngine(templateEngine());
registry.viewResolver(resolver);
}
@Bean
public SpringTemplateEngine templateEngine()
{
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
templateEngine.setEnableSpringELCompiler(true);
return templateEngine;
}
@Bean
public SpringResourceTemplateResolver templateResolver()
{
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
templateResolver.setApplicationContext(applicationContext);
templateResolver.setPrefix("/WEB-INF/");
templateResolver.setSuffix(".html");
return templateResolver;
}
}
SpringMvcDispatcherServletInitializer
package ru.shop.three_d_print.config;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class SpringMvcDispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer
{
@Override
protected Class<?>[] getRootConfigClasses()
{
return null;
}
@Override
protected Class<?>[] getServletConfigClasses()
{
return new Class[] {SpringConfig.class};
}
@Override
protected String[] getServletMappings()
{
return new String[] {"/"};
}
}
指数
<!DOCTYPE html>
<html lang="ru">
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'/>
<title>Title</title>
</head>
<body>
Sentence in english.
Предложение на русском.
build 3 inner
</body>
</html>
结果:
英文句子。?????µ???»???¶?µ?????µ ???° ??????????????. 构建 3 内部
解决方案
我很确定你所要做的就是把它放在你的脑海里!
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
希望它有效!
编辑:我看到你已经在这样做了。你有最新版本的 HTML 吗?如果没有,请尝试更新它
推荐阅读
- or-tools - OrTools 强制按顺序使用车辆
- raspberry-pi3 - 在 Raspberry Pi 3b + 上安装 Cryptowatch
- php - PHP 7.4 错误,注意:尝试访问 bool 类型值的数组偏移量
- powerbi - 将以下 Excel 公式转换为 Dax
- flutter - 使用 .env 文件通过 mockito 进行单元测试
- google-cloud-platform - 输入记录不包含
数据融合领域 - sql - 我在哪里可以找到 master 中的 sys.databases 属性
- python - 如何提取列表中包含关键字的文本句子
- python - 如何将 print() 的结果保存到目录中的 .txt 文件中?
- javascript - react-native 问题中的身份验证流程