JSTL fmt:message and resource bundle result in ???hello?

12,104

A number of things could happen.

When you say

<fmt:setLocale value="en_US" ... />

it means that you should have Messages_en.properties or Messages_en-US.properties. Using

<fmt:setBundle basename="Messages" var="msg" />

you should assign the loaded messages into a variable inside the current scope. When you need to print a message, then, you should use

<fmt:message key="welcome" bundle="${msg}" />

to display the message.

Share:
12,104
Guy
Author by

Guy

Updated on June 04, 2022

Comments

  • Guy
    Guy about 2 years

    i am trying to use JSLT. i followed some instructions.

    1. i've installed a tomcat on xamppp activated it with the control panel and it's working fine on port 8080.
    2. in the WEB-INF\lib directory i've added a "jstl-1.2.jar" file and a Messages_en_US.properties

    this is my test.jsp:

    <fmt:setLocale value="en_US" scope="application"/>
    <fmt:setBundle basename="Messages"/>
    <fmt:message key="welcome" />
    
    <h1>test</h1>
    
    <p>Counting to three:</p>
    <% for (int i=1; i<4; i++) { %>
    <p>This number is <%= i %>.</p>
    <% } %>
    <p>Done counting.</p>
    

    the counting worked so my jsp is valid. but the welcome just shows ???welcome???.

    what am i doing wrong? am i putting the bundles in the right directory? i tried putting the messages bundle in classes and in WEB-INF - no help. i also tried restarting the server - it didn't help.

    how can i use string bundles? how can i use several bundles?

    cheers,