开发者社区> 问答> 正文

springmvc国际化问题 - java报错

我配置了国际化

<!-- 国际化支持 -->
	<mvc:interceptors>
		<ref bean="localeChangeInterceptor" />
	</mvc:interceptors>
	
	<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
		<property name="paramName" value="locale" />
	</bean>
	<bean id="localeResolver"  class="org.springframework.web.servlet.i18n.SessionLocaleResolver"></bean>  
	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
		<property name="basename">
			<value>messages</value>
		</property>
	</bean>


jsp部分代码:

<spring:message code="login.title"/>

访问方式1:

http://localhost:8080/testi18n/hello.do(访问直接返回jsp)

访问方式2:

http://localhost:8080/testi18n/index.jsp


方式1可以正常,但是方式2就报异常了

javax.servlet.jsp.JspTagException: No message found under code 'login.title' for locale 'zh'.


这是为什么呢?



展开
收起
kun坤 2020-06-05 21:52:24 505 0
1 条回答
写回答
取消 提交回答
  • Using message bundles

    Internationalized messages are defined in message bundles accessed by a Spring MessageSource. To create a flow-specific message bundle, simply define messages.propertiesfile(s) in your flow's directory. Create a default messages.properties file and a .properties file for each additional Locale you need to support.

    #messages.properties
    checkinDate=Check in date must be a future date
    notHealthy={0} is bad for your health
    reservationConfirmation=We have processed your reservation - thank you and enjoy your stay

    From within a view or a flow, you may also access message resources using the resourceBundle EL variable:

    <h:outputText value="#{resourceBundle.reservationConfirmation}" />
    对照一下,你的方法是否满足spring mvc Internationalized messages
    2020-06-05 21:52:32
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载