SpringMVC 获取国际化信息(JSTL view,java代码中,超链接可以选择的方式)

国际化:
1.在页面获取:JSTL view
先设置2个国际化资源文件,然后在springmvc.xml中进行配置(resoucebundlemessagesource bean进行配置)
<fmt:message key=“国际化资源文件中对应的key”></fmt:message>
见这个文章中的详细介绍(https://blog.csdn.net/weixin_38626208/article/details/83246877)
2.页面代码

<a href="testGlobal">Test Global</a>

3.Java代码中

@RequestMapping("/testGlobal")
public String testGlobal(HttpServletRequest request){
RequstContext context=new RequstContext(request);
String message=context.getMessage("user.name");//资源文件的Key值
return "success";
}

3.页面当中超链接可以选择的方式
本地化解析器与拦截器
acceptHeaderLocateResolver:根据HTTP请求头的accept-language参数确定本地化的类型,如果没有显式定义本地化解析器,springmvc使用该解析器
-CookieLocalResolver
-SessionLocalResolver:本地化信息存储在session中,根据Session中特定的属性确定本地化类型
-LoaclChangeInteceptor
global页面中代码:

<%@talib="fmt全路径" prefix="fmt"%>
   <a href="global?locale=zh_CN">中文</a>
   <a href="global?locale=en_US">English</a>//将pageEncoding=UTF-8
   <fmt:message key="header"> </fmt:message>//header为国际化资源文件中的key

在springmvc.xml中代码如下:

<bean id="sessionLoalResolver" class="sessionLocalResolver全路径">
<mvc:interceptors>
<bean id="localchangeinterceptor'   class="LocalChangeInceptor全路径"</bean>
<mvc:interceptor>
<mvc:mapping path="/toFormat"/>//拦截资源的设定,如果没有mapping就是拦截所有的请求
<bean id="MyInterceptor" class="MyInterceptor包的全路径“”
</mvc:interceptor>
</mvc:interceptors>
**<mvc:view-controller path="/global"view-name="global">**
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值