首页 技术 正文
技术 2022年11月21日
0 收藏 878 点赞 3,690 浏览 1649 个字
<!--        关于国际化:        1. 在页面上能够根据浏览器语言设置的情况对文本(不是内容), 时间, 数值进行本地化处理        2. 可以在 bean 中获取国际化资源文件 Locale 对应的消息        3. 可以通过超链接切换 Locale, 而不再依赖于浏览器的语言设置情况        解决:        1. 使用 JSTL 的 fmt 标签        2. 在 bean 中注入 ResourceBundleMessageSource 的示例, 使用其对应的 getMessage 方法即可        3. 配置 LocalResolver 和 LocaleChangeInterceptor    -->        <!-- 配置国际化资源文件 -->    <bean id="messageSource"        class="org.springframework.context.support.ResourceBundleMessageSource">        <property name="basename" value="i18n"></property>    </bean>i18n.propertiesi18n_zh_CN.propertiesi18n_en_US.properties使用fmt标签在jsp页面显示i18n信息<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body>    <fmt:message key="i18n.user"></fmt:message>    <br><br>    <a href="i18n2" rel="external nofollow" >I18N2 PAGE</a></body></html>使用超链接国际化需要配置localeResolver<br><br>    <a href="i18n?locale=zh_CH" rel="external nofollow" >中文</a>    <br><br>    <a href="i18n?locale=en_US" rel="external nofollow" >英文</a>    <!-- 配置 SessionLocalResolver -->    <bean id="localeResolver"        class="org.springframework.web.servlet.i18n.SessionLocaleResolver"></bean>    <mvc:interceptors>        <!-- 配置 LocaleChanceInterceptor -->        <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"></bean>    </mvc:interceptors>@Autowired    private ResourceBundleMessageSource messageSource;    @RequestMapping("/i18n")    public String testI18n(Locale locale){        String val = messageSource.getMessage("i18n.user", null, locale);        System.out.println(val);        return "i18n";    }直接跳转不通过controller    <mvc:view-controller path="/i18n" view-name="i18n"/>    <mvc:view-controller path="/i18n2" view-name="i18n2"/>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,105
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,582
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,429
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919