Warm tip: This article is reproduced from serverfault.com, please click

fmt:message prints key with question marks like so "???login.label.username???"

发布于 2015-06-03 10:49:14

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?

Questioner
Kingo Mostafa
Viewed
0
BalusC 2015-06-04 01:43:58

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.