0

I'm using a Properties file to store the String for the JSP application. And then, by using JSTL FMT tags, I display the texts.

The problem is with some of the special characters like ç,ğ,ö,ş,ı etc.

Ex: Comment ça marche gets displayed as Comment ça marche.

On the JSP, I have the following code.

<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@ taglib prefix="tags" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"  %>
<%@ taglib prefix="jstl" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<fmt:setBundle basename="messages/messages_common" var="messages"/>

.
.
.

<fmt:message key="home.text" bundle="${messages}"/>

I found one solution, where it asked to encode the Properties file. Although this being successful, leads problems when maintaining some translations.

How to fix this issue without encoding the properties file?

Thanks and best regards.

Edit:

In the properties file, the text looks like following.

home.text = Comment ça marche

Edit 2:

By encoding I meant doing the following;

native2ascii -encoding UTF-8 messages_common.properties.org messages_common.properties
Nimila Hiranya
  • 4,842
  • 10
  • 35
  • 52
  • 1
    First, work out whether the problem is really about JSP or Spring, or just the properties files. Ideally, reproduce the problem in a console app, e.g. displaying the UTF-16 code points in a string retrieved from the file. Second, clarify what you mean by "encode the Properties file" - it doesn't help that you haven't shown us either the broken or working properties files. – Jon Skeet Aug 17 '17 at 09:26
  • @JonSkeet Thanks for the reply Jon. I have added a sample line from the Properties file. – Nimila Hiranya Aug 17 '17 at 09:31
  • 1
    And what encoding are you using for that? Unless you specify otherwise somewhere, properties files are expected to be in ISO-8859-1. See http://docs.oracle.com/javase/8/docs/api/java/util/Properties.html – Jon Skeet Aug 17 '17 at 09:32
  • 1
    Note that "ğ" isn't representable in ISO-8859-1, so you'd *have* to use `\u011f` or use a different encoding which you specify somewhere. – Jon Skeet Aug 17 '17 at 09:33
  • Okay, so basically your properties file is currently just a UTF-8 text file, rather than being properly formatted as a properties file. So you either need to fine a way of having it *read* as a UTF-8 file, or you need to go through native2ascii. Are you aware that if you're treating it as "just a text file" you'll have problems if you ever want to represent backslashes, for example? – Jon Skeet Aug 17 '17 at 09:35
  • It sounds like basically this is a duplicate of https://stackoverflow.com/questions/28026342 - you can't specify the encoding used by `fmt:setBundle` as far as I can see. If you want to keep the UTF-8 files, I suggest you separate out "the text files used by the translators" from "the properties files used in the code", generating the latter from the former. – Jon Skeet Aug 17 '17 at 09:37
  • I wasn't. Thanks for the heads up. – Nimila Hiranya Aug 17 '17 at 09:37

0 Answers0