Harshit
Harshit

Reputation: 5157

Spring message is not appearing on jsp page

In this code, I am using localization via spring.

welcome-servlet.xml

<bean id="messageSource" 
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="classpath:resources/messages" />
    <property name="defaultEncoding" value="UTF-8" />       
</bean>

<mvc:interceptors>
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
        p:paramName="locale" />
</mvc:interceptors>

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />

login.jsp

<th align="center">
    <h1><spring:message code="login.LogIN" /></h1>
</td>

Error

javax.servlet.jsp.JspTagException: No message found under code 'login.LogIN' for locale 'hi'.
    org.springframework.web.servlet.tags.MessageTag.doEndTag(MessageTag.java:200)
    org.apache.jsp.view.login_jsp._jspx_meth_spring_005fmessage_005f0(login_jsp.java:216)

messages_en.properties

login.LogIN=LogIn

messages_hi.properties

login.LogIN=LogIn

messages path :

src/resources/messages/messages_hi.properties

How to display the spring message correctly?

Upvotes: 0

Views: 1910

Answers (2)

user2575725
user2575725

Reputation:

Problem is path is not complete, try this:

classpath:/resources/messages/messages

Upvotes: 3

ekem chitsiga
ekem chitsiga

Reputation: 5753

Change your basename for the ReloadableResourceBundleMessageSoource to be resources.messages instead of classpath:/resources/messages. Resource bundles are found in the classpath and uses package convention similar to Java classes

Upvotes: 1

Related Questions