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