[英]Tomcat 9 welcome file encoding is wrong
我有一个 index.html 文件:
<!doctype html>
<html lang="fr" class="no-js fontawesome-i2svg-active fontawesome-i2svg-complete">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title>Annuaire Téléphonique</title>
...
我在公开 Spring 应用程序时找到了一个有效的解决方案,具有以下属性
spring.http.encoding.charset=UTF-8 spring.http.encoding.force-response=true
这种行为对我来说仍然很奇怪......
我有同样的问题:
直接访问网址:
我也在使用弹簧靴。
spring.http.encoding.charset=UTF-8 对我不起作用。
这是我的解决方案:)
@Component
public class CustomFilter implements Filter
{
@Override
public void init(FilterConfig filterConfig) throws ServletException
{
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
if (request instanceof HttpServletRequest)
{
String servletPath = ((HttpServletRequest) request).getServletPath();
if (servletPath.equals("/")) {
// do not let tomcat assign text/html;charset=ISO-8859-1
response.setContentType("text/html; charset=UTF-8");
}
}
chain.doFilter(request, response);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.