SpringMVC_国际化

1、导包导入了jstl的时候会自动创建为一个jstlView;可以快速方便的支持国际化功能;
2、可以支持快速国际化;

  • javaWeb国际化步骤;
    1)、得得到一个Locale对象;
    2)、使用ResourceBundle绑定国际化资源文件;
    3)、使用ResourceBundle.getString(“key”);获取到国际化配置文件中的值;
    4)、web页面的国际化,fmt标签库来做;
    <fmt:setLocale>
    <fmt:setBundle >
    <fmt:message>

  • 有了JstlView以后;

1)、让Spring管理国际化资源就行

 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"></property>
        <property name="suffix" value=".jsp"></property>
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
    </bean>
<!--让SpringMVC管理国际化资源文件;配置一个资源文件管理器;id是必须叫messageSource  -->
	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
		<!--  basename指定基础名-->
		<property name="basename" value="i18n"></property>
	</bean>
简化Controller层方法只有return 页面的情况
	
	<!-- 发送一个请求("toLoginPage");直接来到web-inf下的login页面;mvc名称空间下有一个请求映射标签 -->
	<!-- path="":指定哪个请求 
	    view-name:指定映射给哪个视图;
	    走了SpringMVC的整个流程;视图解析。。。。
	    其他的请求就不好使了?
	 -->
	<mvc:view-controller path="/toLoginPage" view-name="login"/>//拼串
	<!-- 开启mvc注解驱动模式;开启了mvc的开挂模式 -->
	<mvc:annotation-driven></mvc:annotation-driven>
	

2)、直接去页面使用<fmt:message>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>

<body>
<h1>这是hello.jsp</h1>
<form >
    <fmt:message key="username"></fmt:message><input type="text"><br>
    <fmt:message key="password"></fmt:message><input type="password"><br>
</form>
</body>
</html>

一定要过SpringMVC的视图解析流程,人家会创建一个jstlView帮你快速国际化;
return也不能写forward:因为forward转发创建的对象的参数只有forwardUrl,没有传入locale

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值