java – . Messages in the properties file do not display UTF-8 characters
As the title indicates, I can only add that if I enter it manually in the HTML file ąę It doesn't matter
View parser:
<bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/templates/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
<property name="cacheable" value="false"/>
<property name="characterEncoding" value="UTF-8"/>
</bean>
<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
</bean>
<bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine" />
<property name="characterEncoding" value="UTF-8"/>
<property name="order" value="1"/>
</bean>
pom. In XML:
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
HTML input example:
<h2><p th:text="#{homepage.greeting}">Welcome</p></h2>
In the tag of the HTML file:
<Meta charset="UTF-8"/>
In IntelliJ idea, I set the project code to UTF-8, and the default code is the attribute file of UTF-8
I really don't know what the problem is When I change locale to PL, this is the output:
Sorry, I haven't posted the picture yet Any help would be appreciated
On the web Try the filter in XML and still have no luck
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Solution
OK, I figured it out. This is a deal:
I have the following code:
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
Option 1: just add another attribute:
<property name="defaultEncoding" value="UTF-8"/>
Option 2: change to:
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages"/>
<property name="defaultEncoding" value="UTF-8"/>
</bean>
If you change it to reloadable, remember to also change the attribute value from "messages" to "classpath: messages" For some reason, if I don't change it, it can't find the mail package
