简体   繁体   中英

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?

问题是路径不完整,请尝试以下操作:

classpath:/resources/messages/messages

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM