The application has en / ru localization, the localization.properties file is located in the webapp / WEB-INF / classes folder. In the file localization_en.properties: local.index.reg = Register. In the file localization_ru.properties: local.index.reg = Register

There is a class:

public class EncodingFilter implements Filter { private String code; @Override public void init(FilterConfig fConfig) { code = fConfig.getInitParameter("character-encoding"); } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { String codeRequest = request.getCharacterEncoding(); if (code != null && !code.equalsIgnoreCase(codeRequest)) { request.setCharacterEncoding(code); response.setCharacterEncoding(code); } chain.doFilter(request, response); } @Override public void destroy() { code = null; } } 

and in the web.xml I am writing accordingly.

 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> 

and for the filter:

  <filter> <filter-name>EncodingFilter</filter-name> <filter-class>controller.filter.EncodingFilter</filter-class> <init-param> <param-name>character-encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>EncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 

On the index.jsp page I prescribe

 <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <fmt:bundle basename="localization"> <fmt:message key="local.index.register" var="register"/> </fmt:bundle> 

and turning to variable

 <h5>${register}</h5> 

When launching the application on the page, symbols of the symbol of the pattern

How to make them appear normally? I use Intellij idea, ApacheTomcat, OS Ubuntu, Chrome browser

  • ru.properties file in some other encoding, not utf-8? - Sergey
  • the file is encoded in utf-8, in the settings of intellij in File Encodig is also utf-8, and there is a tick in front of Transparent native-to asccii conversion - User User
  • If you simply set <h5> Text </ h5> in the index.jsp file, then Cyrillic is displayed, it does not work from the .properties file - User User
  • Try adding pageEncoding in jsp in the first line: <% @ page contentType = "text / html; charset = UTF-8" language = java "pageEncoding =" UTF-8 "%> - Oleksiy Morenets
  • and in the browser looked Content Content heading? Is there a win-1252 encoding? - alex

0