InternalResourceViewResolver

若在项目中使用了JSTL,则SpringMVC会自动把视图由InternalResourceView转为JstlView,若使用JSTL的fmt标签需要在SpringMVC的配置文件中配置国际化资源文件。这样springmvc的view就变成了jstlview

好,我们现在来演示一下如何使用国际化资源文件


首先我们需要把jstl的jar包添加到项目中:jstl.jar、standard.jar


然后我们 需要配置一个国际化资源文件,如图:



对应的内容是:

i18n_zh_CN:

i18n.username=\u7528\u6237\u540D
i18n.password=\u5BC6\u7801


i18n_en_US:

i18n.username=Username
i18n.password=Password


i18n.:

i18n.username=Username
i18n.password=Password

最后我们需要需要在我们springmvc的配置文件里配置国际化资源文件


<!-- 配置国际化文件 -->
   
<bean id="resourceBundleMessageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
       <property name="basename" value="i18n"/>
    </bean>

然后我们在页面中导入fmt标签:<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

最后引用fmt标签 再通过修改浏览器的语言分别改为中文和英语美国可测试看到结果,这里就不再演示了 :

<fmt:message key="i18n.username"></fmt:message><br>
   <fmt:message key="i18n.password"></fmt:message>



猜你喜欢

转载自blog.csdn.net/qq_34800258/article/details/78655698