I am making one web application. In this application i am using maven
, Spring framework
, Hibernate framework
, JSP
, Apache tiles
.
Still this application is in English language. So now my requirement is convert application is in Portuguese language. So i create one properties file for Portuguese language and use this properties file when require.
In my application create two properties file,
1 for english language(messages.properties
), 2 for portuguese language(messages_pt.properties
)
In my jsp page when i fetch value from messages.properties
file at that time working properly but when fetch from messages_pt.propertie
s file at that time not working properly because in messages_pt.properties
file contains some special character
see my both properties file
messages.properties
gas=Gas
messages_pt.properties
gas=Gás
Now come to my question...
In JSP page i am using fmt tag library
for read value by key from properties file
my jsp page is like this
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
..............
</head>
<body>
..............
<fmt:message key="gas" />
</body>
</html>
so when fetching value for gas
key from messages_pt.properties
file at that time getting G�s
value.
I search solution in google and getting some solution but no one can solve my problem
I am applying below solution
1) In JSP page i add contentType in first line and in meta tag. Please see my jsp page above.
2) I added CharacterEncodingFilter
in web.xml
file and this filter is in first filter from start page.
<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>
3) I added defaultEncoding
in messageSourceBean
in xxx-servlet.xml
file
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:properties/messages</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8"/>
<property name="useCodeAsDefaultMessage" value="true"/>
</bean>
4) I added project.build.sourceEncoding
in pom.xml
file.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
.......
</properties>
5) I tried below code
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<p><spring:message code="label.menu"/></p>
But now can solve my problem.
If anybody know any other solution then please tell me.
I got a same issue in my past, I doing the following solution see the attached screenshot.
Go to file properties > Resource >
Change yourc content type to UTF-8
.