国际化
:它们分别是“语言类型”和“国家/地区的类型”。
简单的写有一个例子:
xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="gvn.openlab"></context:component-scan>
<mvc:annotation-driven/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<mvc:view-controller path="/" view-name="index"></mvc:view-controller>
<mvc:view-controller path="/save" view-name="save"></mvc:view-controller>
<mvc:view-controller path="/logn" view-name="logn"></mvc:view-controller>
<!--获取资源文件il8n的内容-->
<bean class="org.springframework.context.support.ResourceBundleMessageSource" id="messageSource">
<property name="defaultEncoding" value="UTF-8"></property>
<property name="basename" value="il8n"></property>
</bean>
<!--判断locale,采用HTTP请求的Accept-Language-->
<bean class="org.springframework.web.servlet.i18n.SessionLocaleResolver" id="localeResolver">
</bean>
<mvc:interceptors>
<!--LocaleChangeInterceptor spring动态改变本地语言-->
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"></bean>
</mvc:interceptors>
</beans>
il8n_en_US.properties和il8n_zh_CN.properties文件
il8n.name:English
il8n.name:汉语
展示jsp文件:
<%--
Created by IntelliJ IDEA.
User: 11960
Date: 2021/9/21
Time: 16:31
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
//JSTL标签提供了对国际化(I18N)的支持,它可以根据发出请求的客户端地域的不同来显示不同的语言。同时还提供了格式化数据和日期的方法。实现这些功能需要I18N格式标签库(I18N-capable formation tags liberary)。引入该标签库的方法为:
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
//I18N格式标签库提供了11个标签,这些 标签从功能上可以划分为3类如下:
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<html>
<head>
<title>Title</title>
</head>
<body>
<a href="${pageContext.request.contextPath}/emp">查看信息<