7

I am trying to internationalize my website using JSTL 1.2 based on How to internationalize a Java web application?. Here is the beginning of the JSP file:

<%@ page pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="language" value="${not empty param.language ? param.language : not empty language ? language : pageContext.request.locale}" scope="session" />
<fmt:setLocale value="${language}" />
<fmt:setBundle basename="com.bundle.test" />
<html lang="${language}">

Here is the test.properties file:

login.label.username = Username
login.label.password = Password
login.button.submit = Sign in
login.label.direction = rlt

In the body, I include those lines:

<label for="username"><fmt:message key="login.label.username" /></label>

But when I open the JSP page in browser, it outputs like this:

???login.label.username???

I expected it to output the value "Username".

How is this caused and how can I solve it?

Community
  • 1
  • 1
Kingo Mostafa
  • 357
  • 5
  • 21

4 Answers4

9

A message in the format ???key??? means that the message associated with the key couldn't be found. This can mean that you typo'ed the key, or that the key is absent in the bundle file, or even that the whole bundle file is absent as resource in runtime classpath.

Given that the key looks good, and is present in the bundle file, this can only mean that the webapp couldn't find the bundle file as classpath resource.

Given that you're using Maven, you should assure that you have placed them in /src/main/resources folder. In your particular case with the bundle name of com.bundle.test, you should have a /src/main/resources/com/bundle/test.properties file exactly there.

If that still doesn't work, then well, your build may be dirty or broken. Clean and rebuild to be sure. Then extract the Maven-produced WAR file using some ZIP tool and explore its contents. It should ultimately end up in /WEB-INF/classes folder like /WEB-INF/classes/com/bundle/test.properties.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

Adding this code in my web.xml solved my problem

<context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>messages</param-value>
</context-param>
Hossam Ali
  • 49
  • 11
0

In case this helps anyone, I was stuck on this issue. I had many profiles in my project with the properties file and the issue in mine was that I had not added the key to all the profiles and so, it was giving me a ??? message.key ??? error. After I added the key to all the profile property files, the issue was resolved.

-1

If some message is ever replaced with ???<key>???, this means that the message key could not be found in the configured resource bundle.

Be sure to add a context init parameter in the deployment descriptor (web.xml). This establishes a resource bundle from which localized messages can be loaded.

<context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>test</param-value>
</context-param>

Then place your test.properties file in the source/production/resources directory of your IDE project.