Spring MVC 国际化

第四十五章 Spring之假如让你来写MVC——国际化篇 对于Spring一直都是既熟悉又陌生,说对它熟悉吧,平时用用没啥问题,但面试的时候被问的一脸懵逼,就很尴尬,都不好意思在简历上写着熟悉Spring了所以决定花点时间研究研究Spring的源码。《Spring源码深度解析(第2版)》、《Spring揭秘》、《Spring技术内幕:深入解析Spring架构与设计原理(第2版)》书接上回,在上篇四十四章Spring之假如让你来写MVC——异常处理器篇中,A君已经完成了异常处理器部分的功能了。接下来看看A君会有什么骚操作吧。 阅读详情
Spring MVC是通过实现了LocaleResolver的类来识别用户的locale

1. org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver
默认的locale resolver 他是通过提取request.header的'Accept-Language'的值来解析

2. org.springframework.web.servlet.i18n.SessionLocaleResolver

Another option of resolving locales is by SessionLocaleResolver. It resolves locales by inspecting
a predefined attribute in a user’s session. If the session attribute doesn’t exist, this locale
resolver will determine the default locale from the accept-language HTTP header.
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="en" />
</bean>
You can set the defaultLocale property for this resolver in case the session attribute
doesn’t exist. Note that this locale resolver is able to change a user’s locale by altering the
session attribute that stores the locale.

3. org.springframework.web.servlet.i18n.CookieLocaleResolver

You can also use CookieLocaleResolver to resolve locales by inspecting a cookie in a user’s
browser. If the cookie doesn’t exist, this locale resolver will determine the default locale from
the accept-language HTTP header.
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />
The cookie used by this locale resolver can be customized by setting the cookieName and
cookieMaxAge properties. The cookieMaxAge property indicates how many seconds this cookie
should be persisted. The value -1 indicates that this cookie will be invalid after the browser is
closed.
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="cookieName" value="language" />
<property name="cookieMaxAge" value="3600" />
<property name="defaultLocale" value="en" />
</bean>

You can also set the defaultLocale property for this resolver in case the cookie doesn’t
exist in a user’s browser. This locale resolver is able to change a user’s locale by altering the
cookie that stores the locale.
Spring MVC国际化开发指南 在Web应用程序中实现国际化是一个常见的需求,它允许应用程序根据用户的语言和地区提供不同的界面文本。在本文中,我们介绍了如何配置国际化资源文件、配置Spring MVC、在控制器中使用国际化文本,并创建相应的视图来展示文本内容。在项目的资源目录下创建一个名为"messages"的文件夹,并在该文件夹下创建多个属性文件,每个文件对应一种语言。在这些资源文件中,我们可以定义键值对,键表示要显示的文本标识符,值表示对应语言的文本内容。这样,根据用户的语言设置,访问"/welcome"路径时将显示对应的欢迎标题。 阅读详情

相关推荐

RTKLIB模糊度固定实战:三种模式对比与部分模糊度固定代码解析

本文深入解析RTKLIB中模糊度固定的三种核心模式(continuous、instantaneous、fix and hold),对比其性能与适用场景,并详细拆解了部分模糊度固定技术的源码实现。通过实战案例与代码级解析,为GNSS高精度定位开发者提供了在不同数据特性下提升固定成功率的优化思路与配置建议。

efc1234567的博客 473

Spring MVC之LocaleResolver详解

【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> ...

爱宝贝丶的博客 1880

SLG大地图实战:从Tilemap到Shader的地表渲染与数据分层架构

本文深入探讨了SLG大地图开发中的关键技术挑战与解决方案,包括Tilemap系统的深度改造、地表渲染的Shader优化以及数据分层架构设计。通过实战案例,展示了如何实现视觉表现丰富、性能开销可控的SLG大地图,特别适合Unity开发者和游戏技术美术参考。

weixin_28693309的博客 525

Spring MVC更多家族成员--国际化视图与LocalResolver---10

网络拉近了人与人之间的距离。所以,现在的Web应用程序尤其是企业级的应用,都会提供国际化的信息支持,以便可以根据访问者的Locale信息为他们提供相应语言的信息内容。LocaleChangeInterceptor的工作原理十分简单,它根据某一个请求参数获取要切换到的Locale 信息(该参数默认名称为“locale”),然后通过相应LocaleResolver实现类的setLocale方法, 使用新获取的Locale信息替换掉所使用的LocaleResolver默认策略所返回的Locale值。...

m0_53157173的博客 757

SAPABAP金色传说:关于导入和导出Excel时反复弹窗提示 SAP GUI安全性问题的解决方法

文章目录前言一、提示的到底是什么?二、关闭SAP GUI安全提示的步骤1.设置位置 前言 如果你在SAP中,经常需要将数据导出Excel,或者使用Excel进行批导数据,那么你对下面这个频繁出现的弹窗提示一定不陌生! 系统试图创建文件 C:\Users\15265\Desktop\EXPORT.XLSX 于目录 C:\Users\15265\Desktop\ 是否要授权修改父目录及其所有子目录? 不管你是不是选的记住我的决定,它必出!就很烦!那如何处理才能关闭呢? 提示:以下是本篇文章正文内容,看完快

Easystudios博客 1万+

基于SVPWM控制策略的二极管钳位型NPC逆变器并网闭环simulink仿真

本文介绍了二极管钳位型三电平SVPWM技术在逆变器中的应用,通过控制IGBT的开关状态,将直流电压转换为三相交流电压,并采用钳位技术降低谐波失真,提高输出质量。文章还描述了基于SVPWM控制策略的二极管钳位型NPC逆变器并网闭环的Simulink仿真模型,该模型实现了并网控制,具有优异的性能,THD小于1%,适用于新手学习。仿真模型参数包括DC 800V、AC 380V、功率100kw,采用三电平NPC拓扑结构和SVPWM闭环控制策略,配备LCL滤波器,生成三电平波形,监测交流侧电压电流、有功功率和无功功率

2510_91195931的博客 468

Spring MVC的CookieLocaleResolver

一配置文件 <?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.sp...

实践求真知 1364

【人工智能AI】是什么?

人工智能(Artificial Intelligence),英文缩写为AI。它是研究、开发用于模拟延伸和扩展人的智能的理论方法技术及应用系统的一门新的技术科学。(百度百科)人工智能的基本原理:机器从「特定的」大量数据中总结规律,形成某些「特定的知识」,然后将这种「知识」应用到现实场景中去解决实际问题。在这个基本原理的基础上,有3个特征:1、人工智能本质上是一种工具2、人工智能技能只能解决特定的问题,而不是什么都能做3、人工智能属于归纳逻辑,可以告诉你是什么,但是不能告诉你为什么。

KJCZ.AK的博客 2万+

Java for Web学习笔记(七四):国际化i18n(2)Locale Resolver

SessionLocaleResolver 判断locale,采用HTTP请求的Accept-Language,如果我们希望还能通过其他途径来设定locale,需要Locale Resolver,即解析出合适的locale,这样,我们就可以允许用户变更语言,而不局限于浏览器的设置。 Spring提供了org.springframework.web.servlet.i18n.SessionLoc

愷风(Wei)的专栏 9286

11、rsa-目标主机支持RSA密钥交换【原理扫描】的漏洞

通过将 etcd 的 TLS 密钥交换算法从 RSA 升级为 ECDHE,可实现前向保密,彻底消除 “私钥泄露导致历史流量解密” 的风险。核心步骤是通过强制启用含ECDHE的套件,并禁用 RSA 密钥交换套件,同时建议升级到 TLS 1.2+ 并优化证书类型(优先 ECDSA)。这一配置符合云原生安全最佳实践,也是 Kubernetes 等依赖 etcd 的系统推荐的安全标准。生成临时密钥的具体步骤是什么?如何验证etcd是否已成功更新为ECDH密钥交换算法?配置临时密钥交换算法可能带来哪些性能影响。

xuebo1129927648的博客 1万+

【滚雪球学数学建模】第4.1节·概率与统计建模,一文搞懂!

🎓 本文收录于 《滚雪球学数学建模》专栏,本专栏专注于从零基础出发,带你循序渐进掌握数学建模的核心方法与思维路径。通过“滚雪球式”学习法,从最简单的生活化案例到经典建模工具,再到省赛、国赛真题实战演练,逐步积累知识与技能,帮助你搭建完整的建模体系。无论你是刚接触建模的新生,还是希望提升科研与竞赛能力的学者与工程师,本专栏都将为你提供一条清晰、高效、可实操的建模成长路线,助力你快速进阶,突破难点,迈向数学建模竞赛与实际应用的更高峰 🚀!

**My Coding Family** 1352

spring 设置web Locale 国际化对应

今天因程序要 做demo 的需要,研究以下spring message 机制,刚开始还以为 ResourceBundleMessageSource 只取page 的Local ,研读spring 的代码 后才发现是可以自定义Local,在网页切换语言时需要用到此功能,只需要设置一下。代码示例如下设置代码 org.springframework.web.servlet.i18n.Cookie

莫理琴的专栏 5453

什么是IQ信号/为什么用IQ信号/IQ调制与解调/IQ包络与相位/IQ不平衡问题

什么是IQ信号/为什么用IQ信号/IQ调制与解调/IQ包络与相位/IQ不平衡问题

jane0819的博客 810

Spring MVC 国际化的三种实现方式

Spring MVC 国际化和拦截器的实现 1. Spring MVC国际化 全球化的Internet需要全球化的软件。全球化软件,意味着一个软件能够很容易地适应不同地区的市场。当一个软件需要在全球范围内使用的时候,就必须考虑在不同的地域和语言环境下的使用情况,最简单的要求就是在用户界面上的信息可以使用本地化语言来表示。就开发者所关心的,软件的全球化意味着国际化和本地化。我们从以下几个方面进行讲解。 1.1 Spring MVC国际化概述 国际化(internationalization:i18.

qq_22075913的博客 3883

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

spring的MVC国际化的设置

一、基于浏览器语言的国际化配置 使用Spring的MVC,并且配置中有配置Resource文件 xml 代码   &lt;!-- 资源文件绑定器 --&gt;             &lt;bean id="messageSource"class="org.springframework.context.support.ResourceBundleMessageSource"&g...

让梦想插上翅膀 292

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Spring MVC处理国际化

spring mvc国际化

Akiler的博客 575

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Spring 的MVC I18N-国际化相关配置

 Spring 的MVC I18N-国际化相关配置 收藏function StorePage(){d=document;t=d.selection?(d.selection.type!=None?d.selection.createRange().text:):(d.getSelection?d.getSelection():);void(keyit=window.open(ht

快乐就好 1297

spring mvc 国际化

国际化:针对不同地区、语言,显示不同的字符等。 步骤: 1、创建资源文件 基名_语言_地区.properties : i18n_zh_CN.properties (i18n :( internationalization的首末字符i和n,18为中间的字符数)是“国际化”的简称) 或不分地区,只区分语言: 基名_语言.properties : i18n_zh.prop...

zyfzhangyafei的专栏 248

Spring MVC国际化配置

一、基于浏览器语言的国际化配置使用Spring的MVC,并且配置中有配置Resource文件                                                其中,message-info是你的properties文件的通用名。如:我的配置文件叫message-info.properties,message-info_

陈谏辉 788

Spring对国际化的支持 (spring mvc 一样)

博客分类: Spring MVCSpring浏览器ServletJSP  一、基于浏览器语言的国际化配置 使用Spring的MVC,并且配置中有配置Resource文件 Xml代码               bean id="messageSource"class="org.springframework.context.support.ResourceBun

4129

java spring mvc jstl国际化

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33753003的博客 216

spring mvc 国际化配置

要使用spring mvc配置国际化,首先用MessageSource来管理国际资源文件: <!-- 国际化资源文件 messageSource配置的是国际化资源文件的路径, classpath:messages指的是classpath路径下的 messages_zh_CN.properties文件和messages_en_US.properties文件 设置“useCodeAsD...

taotao12312的博客 428

spring mvc配置主题和国际化

在web,xml 中需要加上ContextLoaderListener的监听器,否则在解析jsp的时候会报找不到ApplicationContext的错误。 org.springframework.web.context.ContextLoaderListener contextConfigLocation classpath:spring-servlet.

ITString的博客 716

Spring mvc3自己手动写国际化

Spring3 MVC 中:如果使用国际化的形式,如果采用如下形式:   Java代码   sessionListener: @Override    public   void  sessionCreated(HttpSessionEvent se) {       HttpSession session = se.getSessio...

让梦想插上翅膀 173

Spring MVC 国际化机制详解(MessageSource 接口体系)

Spring MVC 国际化机制详解(MessageSource 接口体系)

爱的叹息的专栏 1225
上一篇: springMVC自定义属性编辑器
下一篇: The Nested Set Model
努力突破
博客等级 码龄17年 36粉丝 113原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值