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
pageEncoding
in jsp in the first line: <% @ page contentType = "text / html; charset = UTF-8" language = java "pageEncoding =" UTF-8 "%> - Oleksiy Morenets