开发者社区> 问答> 正文

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'.


这是为什么呢?



展开
收起
montos 2020-05-29 20:44:38 563 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-05-29 20:46:29
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Java Spring Boot开发实战系列课程【第6讲】:Spring Boot 2.0实战MyBatis与优化(Java面试题) 立即下载
Java Spring Boot开发实战系列课程【第7讲】:Spring Boot 2.0安全机制与MVC身份验证实战(Java面试题) 立即下载
Java 8 简明教程 立即下载