LocaleResolver
--抽象Locale获取策略的接口
LocaleChangeInterceptor
--通过参数改变Locale值
例子:SessionLocaleResolver和LocaleChangeInterceptor的结合使用
ApplicationContext-i18n.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: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.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <context:component-scan base-package="com.siyuan.study.springi18n" /> <mvc:interceptors> <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" /> </mvc:interceptors> <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" /> <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/view/" /> <property name="suffix" value=".jsp" /> </bean> </beans>
LocaleController.java
package com.siyuan.study.springi18n; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/locale") public class LocaleController { @RequestMapping("") public String showLocale() { return "locale"; } }
locale.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!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=ISO-8859-1"> <title>Insert title here</title> </head> <%=response.getLocale() %> <body> </body> </html>
启动后测试:
http://localhost:9000/springi18n/locale
zh_CN
http://localhost:9000/springi18n/locale?locale=en_US
en_US
http://localhost:9000/springi18n/locale
en_US
为什么可以通过response获取Locale
DispatcherServlet.java
protected void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response) throws Exception { // Determine locale for request and apply it to the response. Locale locale = this.localeResolver.resolveLocale(request); response.setLocale(locale); ...... }
相关推荐
ojdbc6.jar和orai18n-11.2.0.4.jar
资源来自pypi官网。 资源全名:django_statici18n-1.0.1-py2.py3-none-any.whl
该压缩包包含最新的orai18n-21.1.0.0.jar和orai18n-19.18.0.0.jar该两个版本。 orai18n.jar解决连接oracle时中文乱码问题。解决字符集不支持错误等问题。 orai18n.jar— 用于 JDK 1.2、1.3、1.4 和 1.5 的 NLS 类。...
orai18n
MyI18N-struts国际化实例
orai18n.jar 解决java连接Oracle数据时报错: 不支持的字符集 (在类路径中添加 orai18n.jar): ZHS16GBK
vue 国际化
orai18n.jar 用于处理oracle中文乱码
资源分类:Python库 所属语言:Python 资源全名:django-statici18n-1.1.2.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
最新版本,已试用,管用。解决ojdbc8.jar不支持汉字的问题,字符集ZHS16GBK,oracle开源工具,以用于自己的项目,大家放心使用,哈哈哈,为了凑够50个字符,不容易。
保真,免费
官方离线安装包,亲测可用
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
SpringBoot i18ndemo需要的朋友可以下载
ojdbc6.jar orai18n.jar
webpack-in-loadervue-i18n版本的wepback loader,给出一个简单的demo。... world介绍该loader的主要目的是将国际化资源与项目代码分离维护,这样我们去查找对应文案的时候更加简单方便,如上述demo所示,我们原文件中...